Added example for comments attachment.
* Fixed `onToken` & `tokenize` to return `startLoc` & `endLoc` in token object only when `options.locations` is `true`. * Fixed `onToken` tests. * Added example for generating comments with escodegen.
This commit is contained in:
@@ -28658,80 +28658,76 @@ testFail("for(const x = 0;;);", "Unexpected token (1:4)", {ecmaVersion: 6});
|
||||
var actualTokens = [],
|
||||
expectedTokens = [
|
||||
{
|
||||
type: tokTypes._var,
|
||||
value: "var",
|
||||
start: 0,
|
||||
end: 3,
|
||||
startLoc: {line: 1, column: 0},
|
||||
endLoc: {line: 1, column: 3},
|
||||
type: tokTypes._var,
|
||||
value: "var"
|
||||
endLoc: {line: 1, column: 3}
|
||||
},
|
||||
{
|
||||
type: tokTypes.name,
|
||||
value: "x",
|
||||
start: 4,
|
||||
end: 5,
|
||||
startLoc: {line: 1, column: 4},
|
||||
endLoc: {line: 1, column: 5},
|
||||
type: tokTypes.name,
|
||||
value: "x"
|
||||
endLoc: {line: 1, column: 5}
|
||||
},
|
||||
{
|
||||
type: tokTypes.eq,
|
||||
value: "=",
|
||||
start: 6,
|
||||
end: 7,
|
||||
startLoc: {line: 1, column: 6},
|
||||
endLoc: {line: 1, column: 7},
|
||||
type: tokTypes.eq,
|
||||
value: "="
|
||||
endLoc: {line: 1, column: 7}
|
||||
},
|
||||
{
|
||||
type: tokTypes.parenL,
|
||||
value: undefined,
|
||||
start: 8,
|
||||
end: 9,
|
||||
startLoc: {line: 1, column: 8},
|
||||
endLoc: {line: 1, column: 9},
|
||||
type: tokTypes.parenL,
|
||||
value: undefined
|
||||
endLoc: {line: 1, column: 9}
|
||||
},
|
||||
{
|
||||
type: tokTypes.num,
|
||||
value: 1,
|
||||
start: 9,
|
||||
end: 10,
|
||||
startLoc: {line: 1, column: 9},
|
||||
endLoc: {line: 1, column: 10},
|
||||
type: tokTypes.num,
|
||||
value: 1
|
||||
endLoc: {line: 1, column: 10}
|
||||
},
|
||||
{
|
||||
type: {binop: 9, prefix: true, beforeExpr: true},
|
||||
value: "+",
|
||||
start: 11,
|
||||
end: 12,
|
||||
startLoc: {line: 1, column: 11},
|
||||
endLoc: {line: 1, column: 12},
|
||||
type: {
|
||||
binop: 9,
|
||||
prefix: true,
|
||||
beforeExpr: true
|
||||
},
|
||||
value: "+"
|
||||
endLoc: {line: 1, column: 12}
|
||||
},
|
||||
{
|
||||
type: tokTypes.num,
|
||||
value: 2,
|
||||
start: 13,
|
||||
end: 14,
|
||||
startLoc: {line: 1, column: 13},
|
||||
endLoc: {line: 1, column: 14},
|
||||
type: tokTypes.num,
|
||||
value: 2
|
||||
endLoc: {line: 1, column: 14}
|
||||
},
|
||||
{
|
||||
type: tokTypes.parenR,
|
||||
value: undefined,
|
||||
start: 14,
|
||||
end: 15,
|
||||
startLoc: {line: 1, column: 14},
|
||||
endLoc: {line: 1, column: 15},
|
||||
type: tokTypes.parenR,
|
||||
value: undefined
|
||||
endLoc: {line: 1, column: 15}
|
||||
},
|
||||
{
|
||||
type: tokTypes.eof,
|
||||
value: undefined,
|
||||
start: 15,
|
||||
end: 15,
|
||||
startLoc: {line: 1, column: 15},
|
||||
endLoc: {line: 1, column: 15},
|
||||
type: tokTypes.eof,
|
||||
value: undefined
|
||||
endLoc: {line: 1, column: 15}
|
||||
}
|
||||
];
|
||||
testAssert('var x = (1 + 2)', function assert(ast) {
|
||||
|
||||
Reference in New Issue
Block a user