Skip to content

Commit

Permalink
feat(parser): implemented dynamic import (stage 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 27, 2019
1 parent 501b76c commit 64a54a8
Show file tree
Hide file tree
Showing 11 changed files with 676 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A 100% compliant, self-hosted javascript parser with high focus on both performa
* Emits an ESTree-compatible abstract syntax tree.
* No backtracking
* Reduced memory usage
* Very well tested (~71k unit tests with full code coverage))
* Very well tested (~73 000 unit tests with full code coverage))
* Lightweight - ~71 KB minified

## ESNext features
Expand Down
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.1.13",
"version": "0.1.14",
"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: 6 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export const enum Errors {
InvalidKeyToken,
LabelRedeclaration,
InvalidNestedStatement,
UnknownLabel
UnknownLabel,
InvalidImportTail,
ImportNotOneArg
}

/*@internal*/
Expand Down Expand Up @@ -322,7 +324,9 @@ export const errorMessages: {
[Errors.InvalidKeyToken]: 'Invalid key token',
[Errors.LabelRedeclaration]: "Label '%0' has already been declared",
[Errors.InvalidNestedStatement]: 'continue statement must be nested within an iteration statement',
[Errors.UnknownLabel]: "Undefined label '%0'"
[Errors.UnknownLabel]: "Undefined label '%0'",
[Errors.InvalidImportTail]: 'Trailing comma is disallowed inside import(...) arguments',
[Errors.ImportNotOneArg]: 'import() requires exactly one argument'
};

export class ParseError extends SyntaxError {
Expand Down
13 changes: 7 additions & 6 deletions src/estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface T_Expression {
UnaryExpression: UnaryExpression;
UpdateExpression: UpdateExpression;
BinaryExpression: BinaryExpression;
ImportExpression: ImportExpression;
AssignmentExpression: AssignmentExpression;
LogicalExpression: LogicalExpression;
MemberExpression: MemberExpression;
Expand Down Expand Up @@ -424,15 +425,15 @@ export interface ConditionalExpression extends _Expression<'ConditionalExpressio
consequent: Expression;
}

interface BaseCallExpression extends _Expression<'ThisExObjectExpressionpression'> {
callee: Expression | Super;
arguments: Array<Expression | SpreadElement>;
}

export interface CallExpression extends _Expression<'CallExpression'> {
callee: Expression | Super;
callee: Expression | Import | Super;
arguments: (Expression | SpreadElement)[];
}

export interface Import extends _Node<'Import'> {}

export interface ImportExpression extends _Expression<'Import'> {}

export interface NewExpression extends _Expression<'NewExpression'> {
callee: Expression;
arguments: (Expression | SpreadElement)[];
Expand Down
23 changes: 19 additions & 4 deletions src/lexer/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import { Token } from '../token';
import { ParserState, Flags } from '../common';
import { report, Errors } from '../errors';

/**
* Skips BOM and hasbang (stage 3)
*
* @param parser Parser object
*/
export function skipHashBang(parser: ParserState): void {
let index = parser.index;
if (parser.index === parser.source.length) return;
if (index === parser.length) return;
if (parser.currentCodePoint === Chars.ByteOrderMark) {
parser.currentCodePoint = parser.source.charCodeAt(index++);
parser.currentCodePoint = parser.source.charCodeAt(++index);
parser.index = index;
}

if (index < parser.source.length && parser.source.charCodeAt(index) === Chars.Hash) {
if (index < parser.length && parser.source.charCodeAt(index) === Chars.Hash) {
index++;
if (index < parser.source.length && parser.source.charCodeAt(index) === Chars.Exclamation) {
if (index < parser.length && parser.source.charCodeAt(index) === Chars.Exclamation) {
parser.index = index + 1;
parser.currentCodePoint = parser.source.charCodeAt(parser.index);
skipSingleLineComment(parser);
Expand All @@ -24,6 +29,11 @@ export function skipHashBang(parser: ParserState): void {
}
}

/**
* Skips single line comment
*
* @param parser Parser object
*/
export function skipSingleLineComment(parser: ParserState): Token {
while (parser.index < parser.length) {
if (
Expand All @@ -37,6 +47,11 @@ export function skipSingleLineComment(parser: ParserState): Token {
return Token.WhiteSpace;
}

/**
* Skips multiline comment
*
* @param parser Parser object
*/
export function skipMultiLineComment(parser: ParserState): any {
while (parser.index < parser.length) {
while (CharTypes[parser.currentCodePoint] & CharFlags.Asterisk) {
Expand Down
2 changes: 1 addition & 1 deletion src/meriyah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export function parse(source: string, options: Options | void): ESTree.Program {
return parseSource(source, options, Context.None);
}

export const version = '0.0.1';
export const version = '0.1.14';

0 comments on commit 64a54a8

Please sign in to comment.