[Pkg-javascript-commits] [node-recast] 01/05: New upstream version 0.12.9
Julien Puydt
julien.puydt at laposte.net
Mon Nov 13 06:52:31 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-recast.
commit 5ad92380f093c60f5e1a641aba6165db6371d448
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Mon Nov 13 07:45:06 2017 +0100
New upstream version 0.12.9
---
.travis.yml | 1 +
lib/printer.js | 98 ++++++++++++++++++++++++++++++++++---------------------
package-lock.json | 42 ++++++++++++++++++------
package.json | 10 +++---
test/babylon.js | 75 +++++++++++++++++++++++++++++-------------
5 files changed, 152 insertions(+), 74 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 5c61e31..954feae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
language: node_js
node_js:
+ - "9"
- "8"
- "7"
- "6"
diff --git a/lib/printer.js b/lib/printer.js
index 4b5e911..9c9787b 100644
--- a/lib/printer.js
+++ b/lib/printer.js
@@ -768,6 +768,9 @@ function genericPrintNoParens(path, options, print) {
case "RegExpLiteral": // Babel 6 Literal split
return fromString(n.extra.raw);
+ case "BigIntLiteral": // Babel 7 Literal split
+ return fromString(n.value + "n");
+
case "BooleanLiteral": // Babel 6 Literal split
case "NumericLiteral": // Babel 6 Literal split
case "StringLiteral": // Babel 6 Literal split
@@ -930,24 +933,23 @@ function genericPrintNoParens(path, options, print) {
]);
case "ForOfStatement":
- return concat([
- "for (",
- path.call(print, "left"),
- " of ",
- path.call(print, "right"),
- ")",
- adjustClause(path.call(print, "body"), options)
- ]);
-
case "ForAwaitStatement":
- return concat([
- "for await (",
+ parts.push("for ");
+
+ if (n.await || n.type === "ForAwaitStatement") {
+ parts.push("await ");
+ }
+
+ parts.push(
+ "(",
path.call(print, "left"),
" of ",
path.call(print, "right"),
")",
adjustClause(path.call(print, "body"), options)
- ]);
+ );
+
+ return concat(parts);
case "DoWhileStatement":
var doBody = concat([
@@ -1189,24 +1191,29 @@ function genericPrintNoParens(path, options, print) {
return concat(parts);
case "ClassProperty":
- if (n.static)
+ if (n.static) {
parts.push("static ");
+ }
var key = path.call(print, "key");
+
if (n.computed) {
key = concat(["[", key, "]"]);
- } else if (n.variance === "plus") {
- key = concat(["+", key]);
- } else if (n.variance === "minus") {
- key = concat(["-", key]);
}
+
+ if (n.variance) {
+ key = concat([printVariance(path, print), key]);
+ }
+
parts.push(key);
- if (n.typeAnnotation)
+ if (n.typeAnnotation) {
parts.push(path.call(print, "typeAnnotation"));
+ }
- if (n.value)
+ if (n.value) {
parts.push(" = ", path.call(print, "value"));
+ }
parts.push(";");
return concat(parts);
@@ -1477,12 +1484,8 @@ function genericPrintNoParens(path, options, print) {
return path.call(print, "value");
case "ObjectTypeIndexer":
- var variance =
- n.variance === "plus" ? "+" :
- n.variance === "minus" ? "-" : "";
-
return concat([
- variance,
+ printVariance(path, print),
"[",
path.call(print, "id"),
": ",
@@ -1492,12 +1495,8 @@ function genericPrintNoParens(path, options, print) {
]);
case "ObjectTypeProperty":
- var variance =
- n.variance === "plus" ? "+" :
- n.variance === "minus" ? "-" : "";
-
return concat([
- variance,
+ printVariance(path, print),
path.call(print, "key"),
n.optional ? "?" : "",
": ",
@@ -1575,15 +1574,20 @@ function genericPrintNoParens(path, options, print) {
">"
]);
+ case "Variance":
+ if (n.kind === "plus") {
+ return fromString("+");
+ }
+
+ if (n.kind === "minus") {
+ return fromString("-");
+ }
+
+ return fromString("");
+
case "TypeParameter":
- switch (n.variance) {
- case 'plus':
- parts.push('+');
- break;
- case 'minus':
- parts.push('-');
- break;
- default:
+ if (n.variance) {
+ parts.push(printVariance(path, print));
}
parts.push(path.call(print, 'name'));
@@ -1988,6 +1992,26 @@ function printFlowDeclaration(path, parts) {
return concat(parts);
}
+function printVariance(path, print) {
+ return path.call(function (variancePath) {
+ var value = variancePath.getValue();
+
+ if (value) {
+ if (value === "plus") {
+ return fromString("+");
+ }
+
+ if (value === "minus") {
+ return fromString("-");
+ }
+
+ return print(variancePath);
+ }
+
+ return fromString("");
+ }, "variance");
+}
+
function adjustClause(clause, options) {
if (clause.length > 1)
return concat([" ", clause]);
diff --git a/package-lock.json b/package-lock.json
index 4a7fa78..a3f67ba 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "recast",
- "version": "0.12.8",
+ "version": "0.12.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -23,9 +23,9 @@
"dev": true
},
"ast-types": {
- "version": "0.9.14",
- "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.9.14.tgz",
- "integrity": "sha512-Ebvx7/0lLboCdyEmAw/4GqwBeKIijPveXNiVGhCGCNxc7z26T5he7DC6ARxu8ByKuzUZZcLog+VP8GMyZrBzJw=="
+ "version": "0.10.1",
+ "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.10.1.tgz",
+ "integrity": "sha512-UY7+9DPzlJ9VM8eY0b2TUZcZvF+1pO0hzMtAyjBYKhOmnvRlqYNYnWdtsMj0V16CGaMlpL0G1jnLbLo4AyotuQ=="
},
"babel-code-frame": {
"version": "6.26.0",
@@ -65,6 +65,12 @@
"source-map": "0.5.7"
},
"dependencies": {
+ "babylon": {
+ "version": "6.18.0",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
+ "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
+ "dev": true
+ },
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
@@ -538,6 +544,14 @@
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lodash": "4.17.4"
+ },
+ "dependencies": {
+ "babylon": {
+ "version": "6.18.0",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
+ "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
+ "dev": true
+ }
}
},
"babel-traverse": {
@@ -555,6 +569,14 @@
"globals": "9.18.0",
"invariant": "2.2.2",
"lodash": "4.17.4"
+ },
+ "dependencies": {
+ "babylon": {
+ "version": "6.18.0",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
+ "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
+ "dev": true
+ }
}
},
"babel-types": {
@@ -570,9 +592,9 @@
}
},
"babylon": {
- "version": "6.18.0",
- "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
- "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==",
+ "version": "7.0.0-beta.31",
+ "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.31.tgz",
+ "integrity": "sha512-6lm2mV3S51yEnKmQQNnswoABL1U1H1KHoCCVwdwI3hvIv+W7ya4ki7Aw4o4KxtUHjNKkK5WpZb22rrMMOcJXJQ==",
"dev": true
},
"balanced-match": {
@@ -681,9 +703,9 @@
"dev": true
},
"flow-parser": {
- "version": "0.57.3",
- "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.57.3.tgz",
- "integrity": "sha1-uNJBobHLrgQ6+nl2458mmYjY/jQ=",
+ "version": "0.59.0",
+ "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.59.0.tgz",
+ "integrity": "sha1-9uvK5h/6GH5CCZnUDOCoAfObJjU=",
"dev": true
},
"fs.realpath": {
diff --git a/package.json b/package.json
index 7925e72..4812fc9 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"parsing",
"pretty-printing"
],
- "version": "0.12.8",
+ "version": "0.12.9",
"homepage": "http://github.com/benjamn/recast",
"repository": {
"type": "git",
@@ -22,13 +22,13 @@
"main": "main.js",
"scripts": {
"test": "node ./node_modules/mocha/bin/mocha --reporter spec --full-trace",
- "debug": "node ./node_modules/mocha/bin/mocha --debug-brk --reporter spec"
+ "debug": "node ./node_modules/mocha/bin/mocha --inspect-brk --reporter spec --full-trace"
},
"browser": {
"fs": false
},
"dependencies": {
- "ast-types": "0.9.14",
+ "ast-types": "0.10.1",
"core-js": "^2.4.1",
"esprima": "~4.0.0",
"private": "~0.1.5",
@@ -37,10 +37,10 @@
"devDependencies": {
"babel-core": "^6.23.1",
"babel-preset-es2015": "^6.22.0",
- "babylon": "~6.18.0",
+ "babylon": "~7.0.0-beta.31",
"esprima-fb": "^15001.1001.0-dev-harmony-fb",
"mocha": "~4.0.1",
- "flow-parser": "^0.57.3",
+ "flow-parser": "^0.59.0",
"reify": "^0.12.3",
"semver": "^5.3.0"
},
diff --git a/test/babylon.js b/test/babylon.js
index 0f32fe7..96e4f92 100644
--- a/test/babylon.js
+++ b/test/babylon.js
@@ -4,7 +4,7 @@ var n = recast.types.namedTypes;
var b = recast.types.builders;
var eol = require("os").EOL;
-describe("decorators", function () {
+describe("Babel", function () {
var babelTransform = require("babel-core").transform;
var babelPresetES2015 = require("babel-preset-es2015");
var parseOptions = {};
@@ -18,54 +18,79 @@ describe("decorators", function () {
return;
}
- it("babel 6 printing", function () {
- var code = [
+ it("basic printing", function () {
+ function check(lines) {
+ var code = lines.join(eol);
+ var ast = recast.parse(code, parseOptions);
+ var output = recast.prettyPrint(ast, { tabWidth: 2 }).code;
+ assert.strictEqual(output, code);
+ }
+
+ check([
'"use strict";', // Directive, DirectiveLiteral in Program
'"use strict";', // Directive, DirectiveLiteral in BlockStatement
'function a() {',
' "use strict";',
'}',
- '',
+ ]);
+
+ check([
'function a() {',
' "use strict";',
' b;',
'}',
- '',
+ ]);
+
+ check([
'() => {',
' "use strict";',
'};',
- '',
+ ]);
+
+ check([
'() => {',
' "use strict";',
' b;',
'};',
- '',
+ ]);
+
+ check([
'var a = function a() {',
' "use strict";',
'};',
- '',
+ ]);
+
+ check([
'var a = function a() {',
' "use strict";',
' b;',
'};',
- '',
+ ]);
+
+ check([
'null;', // NullLiteral
'"asdf";', // StringLiteral
'/a/;', // RegExpLiteral
'false;', // BooleanLiteral
'1;', // NumericLiteral
'const find2 = <X>() => {};', // typeParameters
- '',
+ ]);
+
+ check([
'class A<T> {',
' a;',
' a = 1;',
' [a] = 1;', // computed in ClassProperty
'}',
- '',
+ ]);
+
+ check([
'function f<T>(x: empty): T {', // EmptyTypeAnnotation
' return x;',
'}',
- '',
+ ]);
+
+ check([
'var a: {| numVal: number |};', // exact
'const bar1 = (x: number): string => {};',
'declare module.exports: { foo: string }', // DeclareModuleExports
@@ -73,20 +98,28 @@ describe("decorators", function () {
// 'declare class B { foo: () => number }', // interesting failure ref https://github.com/babel/babel/pull/3663
'declare function foo(): number;',
'var A: (a: B) => void;',
- '',
+ ]);
+
+ check([
'async function* a() {', // async in Function
' for await (let x of y) {', // ForAwaitStatement
' x;',
' }',
'}',
- '',
+ ]);
+
+ check([
'class C2<+T, -U> {', // variance
' +p: T = e;',
'}',
- '',
+ ]);
+
+ check([
'type T = { -p: T };',
'type T = { +[k: K]: V };',
- '',
+ ]);
+
+ check([
'class A {',
' static async *z(a, b): number {', // ClassMethod
' b;',
@@ -104,7 +137,9 @@ describe("decorators", function () {
' return 1;',
' }',
'}',
- '',
+ ]);
+
+ check([
'({',
' async *a() {', // ObjectMethod
' b;',
@@ -129,11 +164,7 @@ describe("decorators", function () {
' 1() {},',
' "1"() {}',
'});',
- ].join(eol);
-
- var ast = recast.parse(code, parseOptions);
- var output = recast.prettyPrint(ast, { tabWidth: 2 }).code;
- assert.strictEqual(output, code);
+ ]);
});
it("babel 6: should not wrap IIFE when reusing nodes", function () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-recast.git
More information about the Pkg-javascript-commits
mailing list