Skip to content

Commit

Permalink
feat(parser): added 'sourceFile' option
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 23, 2019
1 parent 99406ac commit 0c62a08
Show file tree
Hide file tree
Showing 11 changed files with 1,954 additions and 751 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ The second argument allows you to specify various options:
| `parenthesizedExpr` | Enable non-standard parenthesized expression node |
| `raw` | Attach raw property to each literal node |
| `ranges` | Append start and end offsets to each node |
| `sourceFile` | Adds a source attribute in every node’s loc object when the locations option is `true`.|
| `webcompat` | Enable [web compability](https://tc39.github.io/ecma262/#sec-additional-ecmascript-features-for-web-browsers) |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "0.5.0",
"version": "0.5.1",
"description": "A 100% compliant, self-hosted javascript parser with high focus on both performance and stability",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down
9 changes: 7 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export interface ParserState {
startIndex: number;
startColumn: number;
startLine: number;
columnOffset: number;
lineOffset: number;
columnPos: number;
linePos: number;
end: number;
token: Token;
tokenValue: any;
Expand All @@ -143,6 +143,7 @@ export interface ParserState {
pattern: string;
flags: string;
};
sourceFile: string | void;
assignable: AssignmentKind | DestructuringKind;
destructible: AssignmentKind | DestructuringKind;
nextCP: number;
Expand Down Expand Up @@ -400,6 +401,10 @@ export function finishNode<T extends Node>(
column: parser.startColumn,
}
};

if (parser.sourceFile) {
node.loc.source = parser.sourceFile;
}
}

return node;
Expand Down
7 changes: 4 additions & 3 deletions src/lexer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const TokenLookup = [
* @param context Context masks
*/
export function nextToken(parser: ParserState, context: Context): void {
parser.flags &= ~Flags.NewLine;
parser.flags = (parser.flags | Flags.NewLine) ^ Flags.NewLine;
parser.startIndex = parser.index;
parser.startColumn = parser.column;
parser.startLine = parser.line;
Expand All @@ -186,8 +186,9 @@ export function scanSingleToken(parser: ParserState, context: Context, state: Sc

while (parser.index < parser.end) {
parser.tokenIndex = parser.index;
parser.columnOffset = parser.column;
parser.lineOffset = parser.line;
parser.columnPos = parser.column;
parser.linePos = parser.line;

const first = parser.nextCP;

if (first <= 0x7e) {
Expand Down
Loading

0 comments on commit 0c62a08

Please sign in to comment.