[Pkg-javascript-commits] [node-acorn-jsx] 330/484: Loose: implement object methods; expose processed options from acorn.
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:51 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit b46b53e1494611856bf4ca35cc9a6cf22ac23453
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Mon Oct 27 00:55:49 2014 +0200
Loose: implement object methods; expose processed options from acorn.
---
acorn.js | 1 +
acorn_loose.js | 29 +++++++++++++++++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/acorn.js b/acorn.js
index ea4121e..ab23dcd 100644
--- a/acorn.js
+++ b/acorn.js
@@ -234,6 +234,7 @@
tokRegexpAllowed = reAllowed;
skipSpace();
};
+ getToken.options = options;
return getToken;
};
diff --git a/acorn_loose.js b/acorn_loose.js
index 9bc5320..0546d19 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -40,14 +40,16 @@
var options, input, fetchToken, context;
+ acorn.defaultOptions.tabSize = 4;
+
exports.parse_dammit = function(inpt, opts) {
if (!opts) opts = {};
input = String(inpt);
if (/^#!.*/.test(input)) input = "//" + input.slice(2);
- options = opts;
if (!opts.tabSize) opts.tabSize = 4;
fetchToken = acorn.tokenize(input, opts);
+ options = fetchToken.options;
sourceFile = options.sourceFile || null;
context = [];
nextLineStart = 0;
@@ -750,18 +752,22 @@
isGenerator = eat(tt.star);
}
parsePropertyName(prop);
- if (!prop.key) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
+ if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
if (eat(tt.colon)) {
+ prop.kind = "init";
prop.value = parseExpression(true);
+ } else if (options.ecmaVersion >= 6 && (token.type === tt.parenL || token.type === tt.braceL)) {
prop.kind = "init";
+ prop.method = true;
+ prop.value = parseMethod(isGenerator);
} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set")) {
prop.kind = prop.key.name;
- prop.key = parsePropertyName() || dummyIdent();
- prop.value = parseFunction(startNode(), false);
+ parsePropertyName(prop);
+ prop.value = parseMethod(false);
} else {
- prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent();
prop.kind = "init";
+ prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent();
prop.shorthand = true;
}
@@ -784,7 +790,8 @@
prop.computed = false;
}
}
- prop.key = (token.type === tt.num || token.type === tt.string) ? parseExprAtom() : parseIdent();
+ var key = (token.type === tt.num || token.type === tt.string) ? parseExprAtom() : parseIdent();
+ prop.key = key || dummyIdent();
}
function parsePropertyAccessor() {
@@ -876,6 +883,16 @@
return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
}
+ function parseMethod(isGenerator) {
+ var node = startNode();
+ initFunction(node);
+ parseFunctionParams(node);
+ node.generator = isGenerator;
+ node.expression = options.ecmaVersion >= 6 && token.type !== tt.braceL;
+ node.body = node.expression ? parseExpression(true) : parseBlock();
+ return finishNode(node, "FunctionExpression");
+ }
+
function parseExprList(close, allowEmpty) {
var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart;
next(); // Opening bracket
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list