unoverload Literal AST node

This commit is contained in:
Sebastian McKenzie
2015-09-01 04:49:16 +01:00
parent 95f061b76e
commit 8d7b3c462f
565 changed files with 3239 additions and 1120 deletions

View File

@@ -32,9 +32,17 @@ pp.checkPropClash = function (prop, propHash) {
let key = prop.key, name;
switch (key.type) {
case "Identifier": name = key.name; break;
case "Literal": name = String(key.value); break;
default: return;
case "Identifier":
name = key.name;
break;
case "StringLiteral":
case "NumberLiteral":
name = String(key.value);
break;
default:
return;
}
let kind = prop.kind;
@@ -377,19 +385,28 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
case tt.regexp:
let value = this.state.value;
node = this.parseLiteral(value.value);
node.regex = {pattern: value.pattern, flags: value.flags};
node = this.parseLiteral(value.value, "RegexLiteral");
node.pattern = value.pattern;
node.flags = value.flags;
return node;
case tt.num: case tt.string:
return this.parseLiteral(this.state.value);
case tt.num:
return this.parseLiteral(this.state.value, "NumberLiteral");
case tt._null: case tt._true: case tt._false:
case tt.string:
return this.parseLiteral(this.state.value, "StringLiteral");
case tt._null:
node = this.startNode();
node.rawValue = node.value = this.match(tt._null) ? null : this.match(tt._true);
this.next();
return this.finishNode(node, "NullLiteral");
case tt._true: case tt._false:
node = this.startNode();
node.rawValue = node.value = this.match(tt._true);
node.raw = this.state.type.keyword;
this.next();
return this.finishNode(node, "Literal");
return this.finishNode(node, "BooleanLiteral");
case tt.parenL:
return this.parseParenAndDistinguishExpression(null, null, canBeArrow);
@@ -443,12 +460,12 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {
}
};
pp.parseLiteral = function (value) {
pp.parseLiteral = function (value, type) {
let node = this.startNode();
node.rawValue = node.value = value;
node.raw = this.input.slice(this.state.start, this.state.end);
this.next();
return this.finishNode(node, "Literal");
return this.finishNode(node, type);
};
pp.parseParenExpression = function () {

View File

@@ -565,7 +565,7 @@ pp.parseClass = function (node, isStatement, optionalId) {
key = this.parsePropertyName(method);
}
if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
key.type === "Literal" && key.value === "constructor")) {
key.type === "StringLiteral" && key.value === "constructor")) {
if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class");
if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier");
if (isGenerator) this.raise(key.start, "Constructor can't be a generator");

View File

@@ -9,7 +9,7 @@ const pp = Parser.prototype;
// Test whether a statement node is the string literal `"use strict"`.
pp.isUseStrict = function (stmt) {
return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict";
return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && stmt.expression.raw.slice(1, -1) === "use strict";
};
// TODO