: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
var params = this.parseFormalParameters();
this.context.allowYield = false;
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
// https://tc39.github.io/ecma262/#sec-generator-function-definitions
Parser.prototype.isStartOfExpression = function () {
var value = this.lookahead.value;
switch (this.lookahead.type) {
start = (value === '[') || (value === '(') || (value === '{') ||
(value === '+') || (value === '-') ||
(value === '!') || (value === '~') ||
(value === '++') || (value === '--') ||
(value === '/') || (value === '/='); // regular expression literal
start = (value === 'class') || (value === 'delete') ||
(value === 'function') || (value === 'let') || (value === 'new') ||
(value === 'super') || (value === 'this') || (value === 'typeof') ||
(value === 'void') || (value === 'yield');
Parser.prototype.parseYieldExpression = function () {
var node = this.createNode();
this.expectKeyword('yield');
if (!this.hasLineTerminator) {
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
delegate = this.match('*');
argument = this.parseAssignmentExpression();
else if (this.isStartOfExpression()) {
argument = this.parseAssignmentExpression();
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.YieldExpression(argument, delegate));
// https://tc39.github.io/ecma262/#sec-class-definitions
Parser.prototype.parseClassElement = function (hasConstructor) {
var token = this.lookahead;
var node = this.createNode();
computed = this.match('[');
key = this.parseObjectPropertyKey();
if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
if ((token.type === 3 /* Identifier */) && !this.hasLineTerminator && (token.value === 'async')) {
var punctuator = this.lookahead.value;
if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') {
key = this.parseObjectPropertyKey();
if (token.type === 3 /* Identifier */) {
if (token.value === 'get' || token.value === 'set') {
this.tolerateUnexpectedToken(token);
else if (token.value === 'constructor') {
this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync);
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === 3 /* Identifier */) {
if (token.value === 'get' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
else if (token.value === 'set' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
if (!kind && key && this.match('(')) {
value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
this.throwUnexpectedToken(this.lookahead);
if (isStatic && this.isPropertyKey(key, 'prototype')) {
this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
if (!isStatic && this.isPropertyKey(key, 'constructor')) {
if (kind !== 'method' || !method || (value && value.generator)) {
this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
if (hasConstructor.value) {
this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
hasConstructor.value = true;
return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
Parser.prototype.parseClassElementList = function () {
var hasConstructor = { value: false };
while (!this.match('}')) {
body.push(this.parseClassElement(hasConstructor));
Parser.prototype.parseClassBody = function () {
var node = this.createNode();
var elementList = this.parseClassElementList();
return this.finalize(node, new Node.ClassBody(elementList));
Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = (identifierIsOptional && (this.lookahead.type !== 3 /* Identifier */)) ? null : this.parseVariableIdentifier();
if (this.matchKeyword('extends')) {
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
Parser.prototype.parseClassExpression = function () {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = (this.lookahead.type === 3 /* Identifier */) ? this.parseVariableIdentifier() : null;
if (this.matchKeyword('extends')) {
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
// https://tc39.github.io/ecma262/#sec-scripts
// https://tc39.github.io/ecma262/#sec-modules
Parser.prototype.parseModule = function () {
this.context.strict = true;
this.context.isModule = true;
var node = this.createNode();
var body = this.parseDirectivePrologues();
while (this.lookahead.type !== 2 /* EOF */) {
body.push(this.parseStatementListItem());
return this.finalize(node, new Node.Module(body));
Parser.prototype.parseScript = function () {
var node = this.createNode();
var body = this.parseDirectivePrologues();
while (this.lookahead.type !== 2 /* EOF */) {
body.push(this.parseStatementListItem());
return this.finalize(node, new Node.Script(body));
// https://tc39.github.io/ecma262/#sec-imports
Parser.prototype.parseModuleSpecifier = function () {
var node = this.createNode();
if (this.lookahead.type !== 8 /* StringLiteral */) {
this.throwError(messages_1.Messages.InvalidModuleSpecifier);
var token = this.nextToken();
var raw = this.getTokenRaw(token);
return this.finalize(node, new Node.Literal(token.value, raw));
// import {<foo as bar>} ...;
Parser.prototype.parseImportSpecifier = function () {
var node = this.createNode();
if (this.lookahead.type === 3 /* Identifier */) {
imported = this.parseVariableIdentifier();
if (this.matchContextualKeyword('as')) {
local = this.parseVariableIdentifier();
imported = this.parseIdentifierName();
if (this.matchContextualKeyword('as')) {
local = this.parseVariableIdentifier();
this.throwUnexpectedToken(this.nextToken());
return this.finalize(node, new Node.ImportSpecifier(local, imported));
Parser.prototype.parseNamedImports = function () {
while (!this.match('}')) {
specifiers.push(this.parseImportSpecifier());
Parser.prototype.parseImportDefaultSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportDefaultSpecifier(local));
// import <* as foo> ...;
Parser.prototype.parseImportNamespaceSpecifier = function () {
var node = this.createNode();
if (!this.matchContextualKeyword('as')) {
this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
Parser.prototype.parseImportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalImportDeclaration);
var node = this.createNode();
this.expectKeyword('import');
if (this.lookahead.type === 8 /* StringLiteral */) {
src = this.parseModuleSpecifier();
specifiers = specifiers.concat(this.parseNamedImports());
else if (this.match('*')) {
specifiers.push(this.parseImportNamespaceSpecifier());
else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
specifiers.push(this.parseImportDefaultSpecifier());
specifiers.push(this.parseImportNamespaceSpecifier());
else if (this.match('{')) {
specifiers = specifiers.concat(this.parseNamedImports());
this.throwUnexpectedToken(this.lookahead);
this.throwUnexpectedToken(this.nextToken());
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
src = this.parseModuleSpecifier();
return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
// https://tc39.github.io/ecma262/#sec-exports
Parser.prototype.parseExportSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
if (this.matchContextualKeyword('as')) {
exported = this.parseIdentifierName();
return this.finalize(node, new Node.ExportSpecifier(local, exported));
Parser.prototype.parseExportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalExportDeclaration);
var node = this.createNode();
this.expectKeyword('export');
if (this.matchKeyword('default')) {
if (this.matchKeyword('function')) {
// export default function foo () {}
// export default function () {}
var declaration = this.parseFunctionDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
else if (this.matchKeyword('class')) {
// export default class foo {}
var declaration = this.parseClassDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
else if (this.matchContextualKeyword('async')) {
// export default async function f () {}
// export default async function () {}
// export default async x => x
var declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression();
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
if (this.matchContextualKeyword('from')) {
this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
// export default (1 + 2);
var declaration = this.match('{') ? this.parseObjectInitializer() :
this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
else if (this.match('*')) {
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
var src = this.parseModuleSpecifier();
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
else if (this.lookahead.type === 4 /* Keyword */) {
var declaration = void 0;
switch (this.lookahead.value) {
declaration = this.parseLexicalDeclaration({ inFor: false });
declaration = this.parseStatementListItem();
this.throwUnexpectedToken(this.lookahead);
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
else if (this.matchAsyncFunction()) {
var declaration = this.parseFunctionDeclaration();
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
var isExportFromIdentifier = false;
while (!this.match('}')) {
isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
specifiers.push(this.parseExportSpecifier());
if (this.matchContextualKeyword('from')) {
// export {default} from 'foo';
// export {foo} from 'foo';
source = this.parseModuleSpecifier();
else if (isExportFromIdentifier) {
// export {default}; // missing fromClause
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
return exportDeclaration;
/***/ function(module, exports) {
// Ensure the condition is true, otherwise throw an error.
// This is only to have a better contract semantic, i.e. another safety net
// to catch a logic error. The condition shall be fulfilled in normal case.
// Do NOT use this to enforce a certain condition on any user input.
Object.defineProperty(exports, "__esModule", { value: true });
function assert(condition, message) {
throw new Error('ASSERT: ' + message);
/***/ function(module, exports) {
/* tslint:disable:max-classes-per-file */
Object.defineProperty(exports, "__esModule", { value: true });
var ErrorHandler = (function () {
function ErrorHandler() {
ErrorHandler.prototype.recordError = function (error) {
ErrorHandler.prototype.tolerate = function (error) {