Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: location for staticlookup and offsetlookup #249

Merged
merged 24 commits into from Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/ast.js
Expand Up @@ -176,10 +176,14 @@ AST.prototype.swapLocations = function(target, first, last, parser) {
target.loc.start = first.loc.start;
target.loc.end = last.loc.end;
if (this.withSource) {
target.loc.source = parser.lexer._input.substring(
target.loc.start.offset,
target.loc.end.offset
);
const startOffset = target.loc.start.offset;
let endOffset = target.loc.end.offset;

if (target.kind === "offsetlookup") {
ichiriac marked this conversation as resolved.
Show resolved Hide resolved
endOffset = endOffset + 1;
}

target.loc.source = parser.lexer._input.substring(startOffset, endOffset);
}
}
};
Expand All @@ -193,7 +197,11 @@ AST.prototype.resolvePrecedence = function(result, parser) {
if (result.kind === "call") {
// including what argument into location
this.swapLocations(result, result.what, result, parser);
} else if (result.kind === "propertylookup") {
} else if (
result.kind === "propertylookup" ||
result.kind === "staticlookup" ||
result.kind === "offsetlookup"
) {
// including what argument into location
this.swapLocations(result, result.what, result.offset, parser);
} else if (result.kind === "bin") {
Expand Down
26 changes: 13 additions & 13 deletions test/snapshot/__snapshots__/acid.test.js.snap
Expand Up @@ -3044,15 +3044,15 @@ Program {
"kind": "offsetlookup",
"loc": Location {
"end": Position {
"column": 30,
"column": 29,
"line": 84,
"offset": 1696,
"offset": 1695,
},
"source": "[++$index]",
"source": "$persians[++$index]",
"start": Position {
"column": 20,
"column": 11,
"line": 84,
"offset": 1686,
"offset": 1677,
},
},
"offset": Pre {
Expand Down Expand Up @@ -4270,15 +4270,15 @@ next:
"kind": "offsetlookup",
"loc": Location {
"end": Position {
"column": 31,
"column": 30,
"line": 125,
"offset": 2747,
"offset": 2746,
},
"source": "[++$i]",
"source": "$this->$x[++$i]",
"start": Position {
"column": 25,
"column": 16,
"line": 125,
"offset": 2741,
"offset": 2732,
},
},
"offset": Pre {
Expand Down Expand Up @@ -6331,11 +6331,11 @@ next:
"line": 97,
"offset": 1982,
},
"source": "::NUMBAR",
"source": "fooBar::NUMBAR",
"start": Position {
"column": 20,
"column": 14,
"line": 97,
"offset": 1974,
"offset": 1968,
},
},
"offset": Identifier {
Expand Down