Skip to content

Commit

Permalink
fix(lexer): fixed issue with PS and LS between tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 8, 2019
1 parent 51fcd14 commit 3dd08b3
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function scanIdentifierSlowCase(

return keyword === void 0
? Token.Identifier
: keyword === Token.YieldKeyword
: keyword === Token.YieldKeyword || !hasEscape
? keyword
: (keyword & Token.FutureReserved) === Token.FutureReserved
? context & Context.Strict && hasEscape
Expand Down
9 changes: 3 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ export interface Options {
directives?: boolean;
// The flag to allow return in the global scope
globalReturn?: boolean;
// The flag to allow await in the global scope
globalAwait?: boolean;
// The flag to enable implied strict mode
impliedStrict?: boolean;
// Enable non-standard parenthesized expression node
Expand All @@ -148,7 +146,6 @@ export function parseSource(source: string, options: Options | void, context: Co
if (options.webCompat) context |= Context.OptionsWebCompat;
if (options.directives) context |= Context.OptionsDirectives | Context.OptionsRaw;
if (options.globalReturn) context |= Context.OptionsGlobalReturn;
if (options.globalAwait) context |= Context.OptionsGlobalAwait;
if (options.raw) context |= Context.OptionsRaw;
if (options.parenthesizedExpr) context |= Context.OptionsParenthesized;
if (options.impliedStrict) context |= Context.Strict;
Expand Down Expand Up @@ -336,10 +333,10 @@ export function parseStatementListItem(
return parseVariableStatement(parser, context, BindingType.Const, BindingOrigin.Statement, start);
case Token.LetKeyword:
return parseLetIdentOrVarDeclarationStatement(parser, context, start);
// ExportDeclaration (only inside modules)
// ExportDeclaration
case Token.ExportKeyword:
report(parser, Errors.InvalidImportExportSloppy, 'export');
// ImportDeclaration (only inside modules)
// ImportDeclaration
case Token.ImportKeyword:
nextToken(parser, context);
switch (parser.token) {
Expand Down Expand Up @@ -488,7 +485,7 @@ export function parseExpressionOrLabelledStatement(
// "let" followed by either "[", "{" or an identifier means a lexical
// declaration, which should not appear here.
// However, ASI may insert a line break before an identifier or a brace.
if (parser.token === Token.LeftBracket && parser.flags & Flags.NewLine) {
if (parser.token === Token.LeftBracket) {
report(parser, Errors.RestricedLetProduction);
}
break;
Expand Down
2 changes: 2 additions & 0 deletions test/parser/declarations/var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ describe('Declarations - Var', () => {
'var 㐀 = 1;',
'var 㘮 = 1;',
'var 䶵',
'var\u2028x\u2028=\u20281\u2028;',
'var\u2029x\u2029=\u20291\u2029;',
'({ __proto__: x, __proto__: y } = {})',
'var { x = 10 } = (o = { x = 20 } = {});',
'var x; (({ x = 10 } = { x = 20 } = {}) => x)({})'
Expand Down
1 change: 0 additions & 1 deletion test/parser/miscellaneous/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe('Expressions - API', () => {
t.deepEqual(
parse('foo', {
loc: true,
globalAwait: true,
globalReturn: true,
ranges: true,
webCompat: true,
Expand Down
1 change: 1 addition & 0 deletions test/parser/statements/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Statements - None', () => {
['"use strict"; if (true) function f() { } else function _f() {}', Context.OptionsWebCompat],
['if (true) const x = null;', Context.None],
['if();', Context.None],
['if (1) let x = 10;', Context.None],
[
`if({1})
{
Expand Down
55 changes: 55 additions & 0 deletions test/parser/statements/labeled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ describe('Statements - Labeled', () => {
['label: class C {};', Context.None],
['label: let x;', Context.None],
['a: async function* a(){}', Context.None],
['if (false) label1: label2: function test262() {} else ;', Context.None],
['label: function* g() {}', Context.None],
['label: const x = null;', Context.None],
['label: function g() {}', Context.Strict],
['label: let x;', Context.None],
['await: 1;', Context.Module],
['bar: function* x() {}', Context.None],
['await: 1;', Context.Strict | Context.Module],
['yield: 1;', Context.Strict],
['foo:for;', Context.None],
Expand Down Expand Up @@ -558,6 +561,58 @@ describe('Statements - Labeled', () => {
sourceType: 'script'
}
],
[
'if (false) {\n L: let\nx = 1; \n }',
Context.None,
{
body: [
{
alternate: null,
consequent: {
body: [
{
body: {
expression: {
name: 'let',
type: 'Identifier'
},
type: 'ExpressionStatement'
},
label: {
name: 'L',
type: 'Identifier'
},
type: 'LabeledStatement'
},
{
expression: {
left: {
name: 'x',
type: 'Identifier'
},
operator: '=',
right: {
type: 'Literal',
value: 1
},
type: 'AssignmentExpression'
},
type: 'ExpressionStatement'
}
],
type: 'BlockStatement'
},
test: {
type: 'Literal',
value: false
},
type: 'IfStatement'
}
],
sourceType: 'script',
type: 'Program'
}
],
[
'L: let\nx',
Context.None,
Expand Down
31 changes: 30 additions & 1 deletion test/parser/statements/with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,39 @@ describe('Statements - With', () => {
['with ({}) function f() {}', Context.None],
['with ({}) let x;', Context.None],
['with ({}) { }', Context.Strict],
[`with (x) foo;`, Context.Strict]
[`with (x) foo;`, Context.Strict],
[`with ({}) let [a] = [42];`, Context.None],
[`with ({}) let [a]`, Context.None],
[`with ({}) let 1`, Context.None],
[`with ({}) let []`, Context.None],
[`while(true) let[a] = 0`, Context.None]
]);

pass('Statements - With (pass)', [
[
'with ({}) let',
Context.None,
{
type: 'Program',
sourceType: 'script',
body: [
{
type: 'WithStatement',
object: {
type: 'ObjectExpression',
properties: []
},
body: {
type: 'ExpressionStatement',
expression: {
type: 'Identifier',
name: 'let'
}
}
}
]
}
],
[
'with ({}) { }',
Context.None,
Expand Down

0 comments on commit 3dd08b3

Please sign in to comment.