Skip to content

Commit

Permalink
fix(parser): renamed deFacto opt to "specDeviation"
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jul 15, 2019
1 parent 6cfbbfd commit d2e7e08
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This is the available options:
// Enable React JSX parsing
jsx: false
// Allow edge cases that deviate from the spec
deFacto: false
specDeviation: false
}
```

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "1.3.3",
"version": "1.3.4",
"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
8 changes: 5 additions & 3 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const enum Context {
DisallowIn = 1 << 27,
InClass = 1 << 28,
OptionsIdentifierPattern = 1 << 29,
OptionsDeFacto = 1 << 30,
OptionsSpecDeviation = 1 << 30,
}

export const enum PropertyKind {
Expand Down Expand Up @@ -160,8 +160,10 @@ export interface ParserState {
* @param parser Parser object
* @param context Context masks
*/
export function consumeSemicolon(parser: ParserState, context: Context): void {
if ((parser.flags & Flags.NewLine) === 0 && (parser.token & Token.IsAutoSemicolon) !== Token.IsAutoSemicolon) {

export function consumeSemicolon(parser: ParserState, context: Context, specDeviation?: number): void {
if ((parser.flags & Flags.NewLine) === 0 && (parser.token & Token.IsAutoSemicolon) !== Token.IsAutoSemicolon
&& !specDeviation) {
report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
}
consumeOpt(parser, context, Token.Semicolon);
Expand Down
18 changes: 4 additions & 14 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export interface Options {
identifierPattern?: boolean;
// Enable React JSX parsing
jsx?: boolean;
//
deFacto?: boolean;
// Allow edge cases that deviate from the spec
specDeviation?: boolean;
}

/**
Expand All @@ -218,7 +218,7 @@ export function parseSource(source: string, options: Options | void, context: Co
if (options.impliedStrict) context |= Context.Strict;
if (options.jsx) context |= Context.OptionsJSX;
if (options.identifierPattern) context |= Context.OptionsIdentifierPattern;
if (options.deFacto) context |= Context.OptionsDeFacto;
if (options.specDeviation) context |= Context.OptionsSpecDeviation;
if (options.source) sourceFile = options.source;
}

Expand Down Expand Up @@ -1695,17 +1695,7 @@ export function parseDoWhileStatement(
consume(parser, context | Context.AllowRegExp, Token.LeftParen);
const test = parseExpressions(parser, context, 1, parser.tokenIndex, parser.linePos, parser.colPos);
consume(parser, context | Context.AllowRegExp, Token.RightParen);
// Fixes edge case where mayority of parser & js engines allowes
// cases like
//
// do;while(0) 0;
//
if (context & Context.OptionsDeFacto) {
consumeOpt(parser, context | Context.AllowRegExp, Token.Semicolon);
// doStatement[?Yield, ?Await, ?Return]while(Expression[+In, ?Yield, ?Await] ) ;
} else {
consumeSemicolon(parser, context | Context.AllowRegExp);
}
consumeSemicolon(parser, context | Context.AllowRegExp, context & Context.OptionsSpecDeviation);
return finishNode(parser, context, start, line, column, {
type: 'DoWhileStatement',
body,
Expand Down
2 changes: 1 addition & 1 deletion test/parser/statements/do-while.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Statements - Do while', () => {
pass('Statements - Do while (pass)', [
[
`do;while(0) 0;`,
Context.OptionsDeFacto,
Context.OptionsSpecDeviation,
{
body: [
{
Expand Down

0 comments on commit d2e7e08

Please sign in to comment.