Skip to content

Commit

Permalink
fix(parser): start with empty label set
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 25, 2019
1 parent 930f825 commit 90d2d78
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ export function parseSource(source: string, options: Options | void, context: Co
// Initialize parser state
const parser = create(source);
skipHashBang(parser);
let labels = { _: 'labels' };

context = context | Context.InGlobal | Context.TopLevel;

return {
type: 'Program',
sourceType: context & Context.Module ? 'module' : 'script',
body:
context & Context.Module ? parseModuleItem(parser, context, labels) : parseStatementList(parser, context, labels)
body: context & Context.Module ? parseModuleItem(parser, context) : parseStatementList(parser, context)
};
}

Expand All @@ -165,7 +164,7 @@ export function parseSource(source: string, options: Options | void, context: Co
* @param parser Parser object
* @param context Context masks
*/
export function parseStatementList(parser: ParserState, context: Context, labels: any): ESTree.Statement[] {
export function parseStatementList(parser: ParserState, context: Context): ESTree.Statement[] {
// StatementList ::
// (StatementListItem)* <end_token>
nextToken(parser, context | Context.AllowRegExp);
Expand All @@ -178,11 +177,11 @@ export function parseStatementList(parser: ParserState, context: Context, labels
while (parser.token === Token.StringLiteral) {
// "use strict" must be the exact literal without escape sequences or line continuation.
if (parser.index - parser.startIndex < 13 && parser.tokenValue === 'use strict') context |= Context.Strict;
statements.push(parseDirective(parser, context, labels));
statements.push(parseDirective(parser, context, /* labels */ {}));
}

while (parser.token !== Token.EOF) {
statements.push(parseStatementListItem(parser, context, { '€': labels }) as ESTree.Statement);
statements.push(parseStatementListItem(parser, context, { '€': {} }) as ESTree.Statement);
}
return statements;
}
Expand All @@ -197,8 +196,7 @@ export function parseStatementList(parser: ParserState, context: Context, labels
*/
export function parseModuleItem(
parser: ParserState,
context: Context,
labels: any
context: Context
): (ReturnType<typeof parseDirective | typeof parseparseModuleItemList>)[] {
// ecma262/#prod-Module
// Module :
Expand All @@ -221,12 +219,12 @@ export function parseModuleItem(
while (parser.token === Token.StringLiteral) {
// "use strict" must be the exact literal without escape sequences or line continuation.
if (parser.index - parser.startIndex < 13 && parser.tokenValue === 'use strict') context |= Context.Strict;
statements.push(parseDirective(parser, context, labels));
statements.push(parseDirective(parser, context, /* labels */ {}));
}
}

while (parser.token !== Token.EOF) {
statements.push(parseparseModuleItemList(parser, context, { '€': labels }) as ESTree.Statement);
statements.push(parseparseModuleItemList(parser, context, { '€': {} }) as ESTree.Statement);
}
return statements;
}
Expand Down

0 comments on commit 90d2d78

Please sign in to comment.