parent
59ec2b2dfb
commit
dc596d73d3
@ -27,22 +27,21 @@ const loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
|
|||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
pp.parseDirective = function () {
|
pp.stmtToDirective = function (stmt) {
|
||||||
let directiveLiteral = this.startNode();
|
let expr = stmt.expression;
|
||||||
let directive = this.startNode();
|
|
||||||
|
|
||||||
let raw = this.input.slice(this.state.start, this.state.end);
|
let directiveLiteral = this.startNodeAt(expr.start, expr.loc.start);
|
||||||
|
let directive = this.startNodeAt(stmt.start, stmt.loc.start);
|
||||||
|
|
||||||
|
let raw = this.input.slice(expr.start, expr.end);
|
||||||
let val = directiveLiteral.value = raw.slice(1, -1); // remove quotes
|
let val = directiveLiteral.value = raw.slice(1, -1); // remove quotes
|
||||||
|
|
||||||
this.addExtra(directiveLiteral, "raw", raw);
|
this.addExtra(directiveLiteral, "raw", raw);
|
||||||
this.addExtra(directiveLiteral, "rawValue", val);
|
this.addExtra(directiveLiteral, "rawValue", val);
|
||||||
|
|
||||||
this.next();
|
directive.value = this.finishNodeAt(directiveLiteral, "DirectiveLiteral", expr.end, expr.loc.end);
|
||||||
|
|
||||||
directive.value = this.finishNode(directiveLiteral, "DirectiveLiteral");
|
return this.finishNodeAt(directive, "Directive", stmt.end, stmt.loc.end);
|
||||||
|
|
||||||
this.semicolon();
|
|
||||||
return this.finishNode(directive, "Directive");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse a single statement.
|
// Parse a single statement.
|
||||||
@ -454,24 +453,19 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
|
|||||||
let octalPosition;
|
let octalPosition;
|
||||||
|
|
||||||
while (!this.eat(end)) {
|
while (!this.eat(end)) {
|
||||||
if (allowDirectives && !parsedNonDirective && this.match(tt.string)) {
|
if (!parsedNonDirective && this.state.containsOctal && !octalPosition) {
|
||||||
let oldState = this.state;
|
|
||||||
let lookahead = this.lookahead();
|
|
||||||
this.state = lookahead;
|
|
||||||
let isDirective = this.isLineTerminator();
|
|
||||||
this.state = oldState;
|
|
||||||
|
|
||||||
if (isDirective) {
|
|
||||||
if (this.state.containsOctal && !octalPosition) {
|
|
||||||
octalPosition = this.state.octalPosition;
|
octalPosition = this.state.octalPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stmt = this.parseDirective();
|
let stmt = this.parseStatement(true, topLevel);
|
||||||
node.directives.push(stmt);
|
|
||||||
|
|
||||||
if (allowDirectives && stmt.value.value === "use strict") {
|
if (allowDirectives && !parsedNonDirective &&
|
||||||
|
stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral") {
|
||||||
|
let directive = this.stmtToDirective(stmt);
|
||||||
|
node.directives.push(directive);
|
||||||
|
|
||||||
|
if (directive.value.value === "use strict") {
|
||||||
oldStrict = this.state.strict;
|
oldStrict = this.state.strict;
|
||||||
this.state.strict = true;
|
|
||||||
this.setStrict(true);
|
this.setStrict(true);
|
||||||
|
|
||||||
if (octalPosition) {
|
if (octalPosition) {
|
||||||
@ -481,10 +475,9 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
parsedNonDirective = true;
|
parsedNonDirective = true;
|
||||||
node.body.push(this.parseStatement(true, topLevel));
|
node.body.push(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldStrict === false) {
|
if (oldStrict === false) {
|
||||||
|
|||||||
2
test/fixtures/core/uncategorised/542/actual.js
vendored
Normal file
2
test/fixtures/core/uncategorised/542/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
"foo"
|
||||||
|
.split(" ")
|
||||||
138
test/fixtures/core/uncategorised/542/expected.json
vendored
Normal file
138
test/fixtures/core/uncategorised/542/expected.json
vendored
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "script",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expression": {
|
||||||
|
"type": "CallExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 17,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"callee": {
|
||||||
|
"type": "MemberExpression",
|
||||||
|
"start": 0,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"object": {
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start": 0,
|
||||||
|
"end": 5,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "foo",
|
||||||
|
"raw": "\"foo\""
|
||||||
|
},
|
||||||
|
"value": "foo"
|
||||||
|
},
|
||||||
|
"property": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 7,
|
||||||
|
"end": 12,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 1
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"name": "split"
|
||||||
|
},
|
||||||
|
"computed": false
|
||||||
|
},
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start": 13,
|
||||||
|
"end": 16,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 7
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 2,
|
||||||
|
"column": 10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": " ",
|
||||||
|
"raw": "\" \""
|
||||||
|
},
|
||||||
|
"value": " "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"directives": []
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user