| 1 |
var code = (function() { |
| 2 |
var kind; |
| 3 |
function readObj() { |
| 4 |
expect('{'); |
| 5 |
if (!skip('}')) { |
| 6 |
do { |
| 7 |
expect('String'); |
| 8 |
expect(':'); |
| 9 |
readVal(); |
| 10 |
} while (skip(',')); |
| 11 |
expect('}'); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
function expect(str) { |
| 16 |
if (kind === str) { |
| 17 |
return lex(); |
| 18 |
} |
| 19 |
throw syntaxError('Expected ' + str + ' but got ' + string.slice(start, end) + '.'); |
| 20 |
} |
| 21 |
|
| 22 |
function readArr() { |
| 23 |
expect('['); |
| 24 |
if (!skip(']')) { |
| 25 |
do { |
| 26 |
readVal(); |
| 27 |
} while (skip(',')); |
| 28 |
expect(']'); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
function readVal() { |
| 33 |
switch (kind) { |
| 34 |
case '[': |
| 35 |
return readArr(); |
| 36 |
case '{': |
| 37 |
return readObj(); |
| 38 |
case 'String': |
| 39 |
return lex(); |
| 40 |
default: |
| 41 |
return expect('Value'); |
| 42 |
} |
| 43 |
} |
| 44 |
}).toString().split('\n').slice(1, -1).join('\n'); |
| 45 |
|
| 46 |
transform(code, { |
| 47 |
plugins: [ |
| 48 |
function (b) { |
| 49 |
var t = b.types; |
| 50 |
return { |
| 51 |
visitor: { |
| 52 |
BinaryExpression: function(path) { |
| 53 |
path.get("left").baseTypeStrictlyMatches(path.get("right")); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
] |
| 59 |
}); |