Compare commits
42 Commits
v7.0.0-alp
...
v7.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f1cd44d60 | ||
|
|
2841945095 | ||
|
|
76060bb2c7 | ||
|
|
84dfa659e7 | ||
|
|
e0b4543601 | ||
|
|
248743e6c5 | ||
|
|
9a1b8ea443 | ||
|
|
55aea26f13 | ||
|
|
fb9a752262 | ||
|
|
4a35243118 | ||
|
|
9fc910d8c0 | ||
|
|
51a293601b | ||
|
|
19c4dd2d8c | ||
|
|
2225892348 | ||
|
|
677160385c | ||
|
|
9b04cbbc4f | ||
|
|
4aca487b6d | ||
|
|
5afe40b095 | ||
|
|
b081f68e87 | ||
|
|
c9ed159a18 | ||
|
|
b9ed9919c1 | ||
|
|
04b4e414ad | ||
|
|
0b890ced19 | ||
|
|
c60bf9a897 | ||
|
|
245c78dcdc | ||
|
|
8a98141b60 | ||
|
|
78544417fc | ||
|
|
c6edce115c | ||
|
|
579499c66d | ||
|
|
827c70e015 | ||
|
|
8a5488e59f | ||
|
|
63204ae51e | ||
|
|
28ae47a174 | ||
|
|
aa684d1b0c | ||
|
|
1fdec955f8 | ||
|
|
213ad1ed7a | ||
|
|
797fb3c2e4 | ||
|
|
9d612e717e | ||
|
|
e919c6e6eb | ||
|
|
d82afb407e | ||
|
|
b858d7ce5e | ||
|
|
b83e0ec7b0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,6 +22,7 @@ package-lock.json
|
||||
/packages/babel-runtime/helpers/es6/*.js
|
||||
!/packages/babel-runtime/helpers/es6/toArray.js
|
||||
/packages/babel-register/test/.babel
|
||||
/packages/babel-cli/test/tmp
|
||||
/packages/*/lib
|
||||
.nyc_output
|
||||
/babel.sublime-workspace
|
||||
|
||||
2
Makefile
2
Makefile
@@ -46,6 +46,8 @@ clean-all:
|
||||
rm -rf packages/*/lib
|
||||
rm -rf node_modules
|
||||
rm -rf packages/*/node_modules
|
||||
rm -rf package-lock.json
|
||||
rm -rf packages/*/package-lock.json
|
||||
make clean
|
||||
|
||||
test-only:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"lerna": "2.0.0-rc.4",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"changelog": {
|
||||
"repo": "babel/babel",
|
||||
"labels": {
|
||||
|
||||
24
package.json
24
package.json
@@ -11,18 +11,18 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "^1.5.0",
|
||||
"babel-cli": "7.0.0-alpha.12",
|
||||
"babel-core": "7.0.0-alpha.12",
|
||||
"babel-eslint": "8.0.0-alpha.12",
|
||||
"babel-plugin-istanbul": "^2.0.1",
|
||||
"babel-preset-env": "2.0.0-alpha.12",
|
||||
"babel-preset-flow": "7.0.0-alpha.12",
|
||||
"babel-preset-stage-0": "7.0.0-alpha.12",
|
||||
"babel-register": "7.0.0-alpha.12",
|
||||
"babel-cli": "7.0.0-alpha.15",
|
||||
"babel-core": "7.0.0-alpha.15",
|
||||
"babel-eslint": "8.0.0-alpha.15",
|
||||
"babel-plugin-istanbul": "^4.1.4",
|
||||
"babel-preset-env": "2.0.0-alpha.15",
|
||||
"babel-preset-flow": "7.0.0-alpha.15",
|
||||
"babel-preset-stage-0": "7.0.0-alpha.15",
|
||||
"babel-register": "7.0.0-alpha.15",
|
||||
"browserify": "^13.1.1",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chai": "^3.5.0",
|
||||
"chalk": "^1.1.1",
|
||||
"chai": "^4.1.0",
|
||||
"chalk": "^2.0.0",
|
||||
"derequire": "^2.0.2",
|
||||
"eslint": "^3.14.1",
|
||||
"eslint-config-babel": "^7.0.1",
|
||||
@@ -41,8 +41,8 @@
|
||||
"lint-staged": "^3.6.1",
|
||||
"lodash": "^4.2.0",
|
||||
"mocha": "^3.0.0",
|
||||
"nyc": "^10.0.0",
|
||||
"output-file-sync": "^1.1.1",
|
||||
"nyc": "^11.0.3",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"prettier": "^1.5.0",
|
||||
"rimraf": "^2.4.3",
|
||||
"semver": "^5.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-cli",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Babel command line.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -16,24 +16,24 @@
|
||||
"compiler"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-core": "7.0.0-alpha.15",
|
||||
"babel-polyfill": "7.0.0-alpha.15",
|
||||
"babel-register": "7.0.0-alpha.15",
|
||||
"babel-core": "7.0.0-alpha.16",
|
||||
"babel-polyfill": "7.0.0-alpha.16",
|
||||
"babel-register": "7.0.0-alpha.16",
|
||||
"commander": "^2.8.1",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"fs-readdir-recursive": "^1.0.0",
|
||||
"glob": "^7.0.0",
|
||||
"lodash": "^4.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"output-file-sync": "^2.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.5.0",
|
||||
"v8flags": "^2.0.10"
|
||||
"v8flags": "^3.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"chokidar": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-fixtures": "7.0.0-alpha.15"
|
||||
"babel-helper-fixtures": "7.0.0-alpha.16"
|
||||
},
|
||||
"bin": {
|
||||
"babel-doctor": "./bin/babel-doctor.js",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-code-frame",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,8 +8,11 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-code-frame",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"chalk": "^1.1.0",
|
||||
"chalk": "^2.0.0",
|
||||
"esutils": "^2.0.2",
|
||||
"js-tokens": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"strip-ansi": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from "assert";
|
||||
import chalk from "chalk";
|
||||
import stripAnsi from "strip-ansi";
|
||||
import codeFrame, { codeFrameColumns } from "..";
|
||||
|
||||
describe("babel-code-frame", function() {
|
||||
@@ -100,7 +101,7 @@ describe("babel-code-frame", function() {
|
||||
it("opts.highlightCode", function() {
|
||||
const rawLines = "console.log('babel')";
|
||||
const result = codeFrame(rawLines, 1, 9, { highlightCode: true });
|
||||
const stripped = chalk.stripColor(result);
|
||||
const stripped = stripAnsi(result);
|
||||
assert.ok(result.length > stripped.length);
|
||||
assert.equal(
|
||||
stripped,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Babel compiler core.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -25,14 +25,14 @@
|
||||
"./lib/config/loading/files/index.js": "./lib/config/loading/files/index-browser.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-code-frame": "7.0.0-alpha.15",
|
||||
"babel-generator": "7.0.0-alpha.15",
|
||||
"babel-helpers": "7.0.0-alpha.15",
|
||||
"babel-messages": "7.0.0-alpha.15",
|
||||
"babel-template": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15",
|
||||
"babylon": "7.0.0-beta.15",
|
||||
"babel-code-frame": "7.0.0-alpha.16",
|
||||
"babel-generator": "7.0.0-alpha.16",
|
||||
"babel-helpers": "7.0.0-alpha.16",
|
||||
"babel-messages": "7.0.0-alpha.16",
|
||||
"babel-template": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16",
|
||||
"babylon": "7.0.0-beta.17",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"debug": "^2.1.1",
|
||||
"json5": "^0.5.0",
|
||||
@@ -42,7 +42,7 @@
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.15",
|
||||
"babel-register": "7.0.0-alpha.15"
|
||||
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.16",
|
||||
"babel-register": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,6 @@ export default class File extends Store {
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = true;
|
||||
ref._generated = true;
|
||||
ref.id = uid;
|
||||
ref.type = "FunctionDeclaration";
|
||||
this.path.unshiftContainer("body", ref);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _values = values;
|
||||
value = _values[fieldName];
|
||||
rest = babelHelpers.objectWithoutProperties(_values, [fieldName]);
|
||||
var _fieldName = fieldName;
|
||||
value = _values[_fieldName];
|
||||
rest = babelHelpers.objectWithoutProperties(_values, [_fieldName].map(babelHelpers.toPropertyKey));
|
||||
_values;
|
||||
var error = void 0;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-generator",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Turns an AST into code.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -11,15 +11,15 @@
|
||||
"lib"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-messages": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15",
|
||||
"jsesc": "^1.3.0",
|
||||
"babel-messages": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16",
|
||||
"jsesc": "^2.5.1",
|
||||
"lodash": "^4.2.0",
|
||||
"source-map": "^0.5.0",
|
||||
"trim-right": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-fixtures": "7.0.0-alpha.15",
|
||||
"babylon": "^7.0.0-beta.15"
|
||||
"babel-helper-fixtures": "7.0.0-alpha.16",
|
||||
"babylon": "^7.0.0-beta.17"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,13 +91,6 @@ export function Decorator(node: Object) {
|
||||
this.newline();
|
||||
}
|
||||
|
||||
function commaSeparatorNewline() {
|
||||
this.token(",");
|
||||
this.newline();
|
||||
|
||||
if (!this.endsWith("\n")) this.space();
|
||||
}
|
||||
|
||||
export function CallExpression(node: Object) {
|
||||
this.print(node.callee, node);
|
||||
|
||||
@@ -105,23 +98,7 @@ export function CallExpression(node: Object) {
|
||||
this.token("?.");
|
||||
}
|
||||
this.token("(");
|
||||
|
||||
const isPrettyCall = node._prettyCall;
|
||||
|
||||
let separator;
|
||||
if (isPrettyCall) {
|
||||
separator = commaSeparatorNewline;
|
||||
this.newline();
|
||||
this.indent();
|
||||
}
|
||||
|
||||
this.printList(node.arguments, node, { separator });
|
||||
|
||||
if (isPrettyCall) {
|
||||
this.newline();
|
||||
this.dedent();
|
||||
}
|
||||
|
||||
this.printList(node.arguments, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as t from "babel-types";
|
||||
import { ExportAllDeclaration } from "./modules";
|
||||
|
||||
export function AnyTypeAnnotation() {
|
||||
this.word("any");
|
||||
@@ -41,9 +42,28 @@ export function DeclareFunction(node: Object, parent: Object) {
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.id.typeAnnotation.typeAnnotation, node);
|
||||
|
||||
if (node.predicate) {
|
||||
this.space();
|
||||
this.print(node.predicate, node);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function InferredPredicate(/*node: Object*/) {
|
||||
this.token("%");
|
||||
this.word("checks");
|
||||
}
|
||||
|
||||
export function DeclaredPredicate(node: Object) {
|
||||
this.token("%");
|
||||
this.word("checks");
|
||||
this.token("(");
|
||||
this.print(node.value, node);
|
||||
this.token(")");
|
||||
}
|
||||
|
||||
export function DeclareInterface(node: Object) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
@@ -100,17 +120,10 @@ export function DeclareExportDeclaration(node: Object) {
|
||||
FlowExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
export function DeclareExportAllDeclaration(node: Object) {
|
||||
export function DeclareExportAllDeclaration(/*node: Object*/) {
|
||||
this.word("declare");
|
||||
this.space();
|
||||
this.word("export");
|
||||
this.space();
|
||||
this.token("*");
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
this.semicolon();
|
||||
ExportAllDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
function FlowExportDeclaration(node: Object) {
|
||||
|
||||
@@ -49,6 +49,16 @@ export function _method(node: Object) {
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
export function _predicate(node: Object) {
|
||||
if (node.predicate) {
|
||||
if (!node.returnType) {
|
||||
this.token(":");
|
||||
}
|
||||
this.space();
|
||||
this.print(node.predicate, node);
|
||||
}
|
||||
}
|
||||
|
||||
export function FunctionExpression(node: Object) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
@@ -65,6 +75,8 @@ export function FunctionExpression(node: Object) {
|
||||
}
|
||||
|
||||
this._params(node);
|
||||
this._predicate(node);
|
||||
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
@@ -89,6 +101,8 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
this._predicate(node);
|
||||
|
||||
this.space();
|
||||
this.token("=>");
|
||||
this.space();
|
||||
|
||||
@@ -44,6 +44,10 @@ export function ExportNamespaceSpecifier(node: Object) {
|
||||
export function ExportAllDeclaration(node: Object) {
|
||||
this.word("export");
|
||||
this.space();
|
||||
if (node.exportKind === "type") {
|
||||
this.word("type");
|
||||
this.space();
|
||||
}
|
||||
this.token("*");
|
||||
this.space();
|
||||
this.word("from");
|
||||
|
||||
@@ -123,8 +123,8 @@ function buildLabelStatement(prefix, key = "label") {
|
||||
const label = node[key];
|
||||
if (label) {
|
||||
this.space();
|
||||
|
||||
const terminatorState = this.startTerminatorless();
|
||||
const isLabel = key == "label";
|
||||
const terminatorState = this.startTerminatorless(isLabel);
|
||||
this.print(label, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
}
|
||||
@@ -171,10 +171,12 @@ export function TryStatement(node: Object) {
|
||||
export function CatchClause(node: Object) {
|
||||
this.word("catch");
|
||||
this.space();
|
||||
this.token("(");
|
||||
this.print(node.param, node);
|
||||
this.token(")");
|
||||
this.space();
|
||||
if (node.param) {
|
||||
this.token("(");
|
||||
this.print(node.param, node);
|
||||
this.token(")");
|
||||
this.space();
|
||||
}
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ export default class Printer {
|
||||
_insideAux: boolean = false;
|
||||
_printedCommentStarts: Object = {};
|
||||
_parenPushNewlineState: ?Object = null;
|
||||
_noLineTerminator: boolean = false;
|
||||
_printAuxAfterOnNextUserNode: boolean = false;
|
||||
_printedComments: WeakSet = new WeakSet();
|
||||
_endsWithInteger = false;
|
||||
@@ -281,7 +282,7 @@ export default class Printer {
|
||||
*
|
||||
* This is to prevent breaking semantics for terminatorless separator nodes. eg:
|
||||
*
|
||||
* return foo;
|
||||
* return foo;
|
||||
*
|
||||
* returns `foo`. But if we do:
|
||||
*
|
||||
@@ -291,10 +292,15 @@ export default class Printer {
|
||||
* `undefined` will be returned and not `foo` due to the terminator.
|
||||
*/
|
||||
|
||||
startTerminatorless(): Object {
|
||||
return (this._parenPushNewlineState = {
|
||||
printed: false,
|
||||
});
|
||||
startTerminatorless(isLabel: boolean = false): Object {
|
||||
if (isLabel) {
|
||||
this._noLineTerminator = true;
|
||||
return null;
|
||||
} else {
|
||||
return (this._parenPushNewlineState = {
|
||||
printed: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +308,8 @@ export default class Printer {
|
||||
*/
|
||||
|
||||
endTerminatorless(state: Object) {
|
||||
if (state.printed) {
|
||||
this._noLineTerminator = false;
|
||||
if (state && state.printed) {
|
||||
this.dedent();
|
||||
this.newline();
|
||||
this.token(")");
|
||||
@@ -319,7 +326,6 @@ export default class Printer {
|
||||
|
||||
const printMethod = this[node.type];
|
||||
if (!printMethod) {
|
||||
// eslint-disable-next-line max-len
|
||||
throw new ReferenceError(
|
||||
`unknown node of type ${JSON.stringify(
|
||||
node.type,
|
||||
@@ -531,13 +537,19 @@ export default class Printer {
|
||||
const isBlockComment = comment.type === "CommentBlock";
|
||||
|
||||
// Always add a newline before a block comment
|
||||
this.newline(this._buf.hasContent() && isBlockComment ? 1 : 0);
|
||||
this.newline(
|
||||
this._buf.hasContent() && !this._noLineTerminator && isBlockComment
|
||||
? 1
|
||||
: 0,
|
||||
);
|
||||
|
||||
if (!this.endsWith("[") && !this.endsWith("{")) this.space();
|
||||
|
||||
let val = !isBlockComment ? `//${comment.value}\n` : `/*${comment.value}*/`;
|
||||
let val =
|
||||
!isBlockComment && !this._noLineTerminator
|
||||
? `//${comment.value}\n`
|
||||
: `/*${comment.value}*/`;
|
||||
|
||||
//
|
||||
if (isBlockComment && this.format.indent.adjustMultilineComment) {
|
||||
const offset = comment.loc && comment.loc.start.column;
|
||||
if (offset) {
|
||||
@@ -560,7 +572,7 @@ export default class Printer {
|
||||
});
|
||||
|
||||
// Always add a newline after a block comment
|
||||
this.newline(isBlockComment ? 1 : 0);
|
||||
this.newline(isBlockComment && !this._noLineTerminator ? 1 : 0);
|
||||
}
|
||||
|
||||
_printComments(comments?: Array<Object>) {
|
||||
|
||||
@@ -22,3 +22,5 @@ declare module B {
|
||||
declare export type B = {};
|
||||
declare export interface Moon {}
|
||||
}
|
||||
|
||||
declare module "foo" { declare export type * from "bar"; }
|
||||
|
||||
@@ -29,4 +29,7 @@ declare export { c, d } from 'bar';
|
||||
declare module B {
|
||||
declare export type B = {};
|
||||
declare export interface Moon {}
|
||||
}
|
||||
declare module "foo" {
|
||||
declare export type * from "bar";
|
||||
}
|
||||
17
packages/babel-generator/test/fixtures/flow/predicates/actual.js
vendored
Normal file
17
packages/babel-generator/test/fixtures/flow/predicates/actual.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
declare function foo(x: mixed): boolean %checks(x !== null);
|
||||
|
||||
declare function my_filter<T, P: $Pred<1>>(v: Array<T>, cb: P): Array<$Refine<T,P,1>>;
|
||||
|
||||
declare function f2(x: mixed): string %checks(Array.isArray(x));
|
||||
|
||||
function foo(x: mixed): %checks { return typeof x === "string"; }
|
||||
|
||||
function is_string(x): boolean %checks {
|
||||
return typeof x === "string";
|
||||
}
|
||||
|
||||
var f = (x: mixed): %checks => typeof x === "string";
|
||||
|
||||
const foo = (x: mixed): boolean %checks => typeof x === "string";
|
||||
|
||||
(x): %checks => x !== null;
|
||||
17
packages/babel-generator/test/fixtures/flow/predicates/expected.js
vendored
Normal file
17
packages/babel-generator/test/fixtures/flow/predicates/expected.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
declare function foo(x: mixed): boolean %checks(x !== null);
|
||||
declare function my_filter<T, P: $Pred<1>>(v: Array<T>, cb: P): Array<$Refine<T, P, 1>>;
|
||||
declare function f2(x: mixed): string %checks(Array.isArray(x));
|
||||
|
||||
function foo(x: mixed): %checks {
|
||||
return typeof x === "string";
|
||||
}
|
||||
|
||||
function is_string(x): boolean %checks {
|
||||
return typeof x === "string";
|
||||
}
|
||||
|
||||
var f = (x: mixed): %checks => typeof x === "string";
|
||||
|
||||
const foo = (x: mixed): boolean %checks => typeof x === "string";
|
||||
|
||||
x: %checks => x !== null;
|
||||
@@ -123,3 +123,4 @@ var a: {| subtract: (x: number, ...y: Array<string>) => void |};
|
||||
var a: {| id<T>(x: T): T; |};
|
||||
function foo(numVal: number = 2) {}
|
||||
function foo(numVal?: number = 2) {}
|
||||
export type * from "foo";
|
||||
|
||||
@@ -286,4 +286,6 @@ var a: {|
|
||||
|
||||
function foo(numVal: number = 2) {}
|
||||
|
||||
function foo(numVal?: number = 2) {}
|
||||
function foo(numVal?: number = 2) {}
|
||||
|
||||
export type * from "foo";
|
||||
13
packages/babel-generator/test/fixtures/parentheses/break-statement/actual.js
vendored
Normal file
13
packages/babel-generator/test/fixtures/parentheses/break-statement/actual.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
label1: for (const a of [1, 2, 3]) {
|
||||
break /*Block comment written in single line */ label1;
|
||||
}
|
||||
|
||||
label2: for (const a of [1, 2, 3]) {
|
||||
break /*Block comment written
|
||||
in multiple lines */ label2;
|
||||
}
|
||||
|
||||
label2: for (const a of [1, 2, 3]) {
|
||||
break //foo
|
||||
label2;
|
||||
}
|
||||
17
packages/babel-generator/test/fixtures/parentheses/break-statement/expected.js
vendored
Normal file
17
packages/babel-generator/test/fixtures/parentheses/break-statement/expected.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
label1: for (const a of [1, 2, 3]) {
|
||||
break /*Block comment written in single line */label1;
|
||||
}
|
||||
|
||||
label2: for (const a of [1, 2, 3]) {
|
||||
break;
|
||||
/*Block comment written
|
||||
in multiple lines */
|
||||
|
||||
label2;
|
||||
}
|
||||
|
||||
label2: for (const a of [1, 2, 3]) {
|
||||
break; //foo
|
||||
|
||||
label2;
|
||||
}
|
||||
@@ -11,3 +11,4 @@ false;
|
||||
0o70;
|
||||
0X1F;
|
||||
-0b1111011;
|
||||
"use strict";
|
||||
@@ -11,3 +11,4 @@ false;
|
||||
0o70;
|
||||
0X1F;
|
||||
-0b1111011;
|
||||
"use strict";
|
||||
@@ -1,2 +1,4 @@
|
||||
foo ||bar;
|
||||
(x => x)|| bar;
|
||||
(function a(x){return x;})|| 2;
|
||||
0||(function(){return alpha;});
|
||||
@@ -1,2 +1,10 @@
|
||||
foo || bar;
|
||||
(x => x) || bar;
|
||||
|
||||
(function a(x) {
|
||||
return x;
|
||||
}) || 2;
|
||||
|
||||
0 || function () {
|
||||
return alpha;
|
||||
};
|
||||
51
packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/actual.js
vendored
Normal file
51
packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/actual.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
try {} catch (err) {}
|
||||
|
||||
try {} catch {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
} finally {
|
||||
yay();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
} finally {
|
||||
yay();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
} finally {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
} finally {}
|
||||
51
packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/expected.js
vendored
Normal file
51
packages/babel-generator/test/fixtures/types/Optional-TryStatement-CatchClause/expected.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
try {} catch (err) {}
|
||||
|
||||
try {} catch {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
} finally {
|
||||
yay();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
} finally {
|
||||
yay();
|
||||
}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch (err) {
|
||||
foo();
|
||||
} finally {}
|
||||
|
||||
try {
|
||||
bar;
|
||||
} catch {
|
||||
foo();
|
||||
} finally {}
|
||||
@@ -1,5 +1,5 @@
|
||||
import Printer from "../lib/printer";
|
||||
import generate from "../lib";
|
||||
import generate, { CodeGenerator } from "../lib";
|
||||
import assert from "assert";
|
||||
import { parse } from "babylon";
|
||||
import chai from "chai";
|
||||
@@ -11,6 +11,7 @@ import fixtures from "babel-helper-fixtures";
|
||||
describe("generation", function() {
|
||||
it("completeness", function() {
|
||||
Object.keys(t.VISITOR_KEYS).forEach(function(type) {
|
||||
if (type.startsWith("TS")) return; // TODO
|
||||
assert.ok(!!Printer.prototype[type], type + " should exist");
|
||||
});
|
||||
|
||||
@@ -351,6 +352,14 @@ describe("programmatic generation", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("CodeGenerator", function() {
|
||||
it("generate", function() {
|
||||
const codeGen = new CodeGenerator(t.numericLiteral(123));
|
||||
const code = codeGen.generate().code;
|
||||
assert.equal(parse(code).program.body[0].expression.value, 123);
|
||||
});
|
||||
});
|
||||
|
||||
const suites = fixtures(`${__dirname}/fixtures`);
|
||||
|
||||
suites.forEach(function(testSuite) {
|
||||
@@ -380,6 +389,7 @@ suites.forEach(function(testSuite) {
|
||||
"jsx",
|
||||
"objectRestSpread",
|
||||
"optionalChaining",
|
||||
"optionalCatchBinding",
|
||||
],
|
||||
strictMode: false,
|
||||
sourceType: "module",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "babel-helper-bindify-decorators",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to bindify decorators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-bindify-decorators",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "babel-helper-builder-binary-assignment-operator-visitor",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to build binary assignment operator visitors",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-binary-assignment-operator-visitor",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-explode-assignable-expression": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-explode-assignable-expression": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,53 +2,30 @@ import explode from "babel-helper-explode-assignable-expression";
|
||||
import * as t from "babel-types";
|
||||
|
||||
export default function(opts: { build: Function, operator: string }): Object {
|
||||
const visitor = {};
|
||||
const { build, operator } = opts;
|
||||
|
||||
function isAssignment(node) {
|
||||
return node && node.operator === opts.operator + "=";
|
||||
}
|
||||
return {
|
||||
AssignmentExpression(path) {
|
||||
const { node, scope } = path;
|
||||
if (node.operator !== operator + "=") return;
|
||||
|
||||
function buildAssignment(left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
}
|
||||
const nodes = [];
|
||||
const exploded = explode(node.left, nodes, this, scope);
|
||||
nodes.push(
|
||||
t.assignmentExpression(
|
||||
"=",
|
||||
exploded.ref,
|
||||
build(exploded.uid, node.right),
|
||||
),
|
||||
);
|
||||
path.replaceWith(t.sequenceExpression(nodes));
|
||||
},
|
||||
|
||||
visitor.ExpressionStatement = function(path, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (path.isCompletionRecord()) return;
|
||||
|
||||
const expr = path.node.expression;
|
||||
if (!isAssignment(expr)) return;
|
||||
|
||||
const nodes = [];
|
||||
const exploded = explode(expr.left, nodes, file, path.scope, true);
|
||||
|
||||
nodes.push(
|
||||
t.expressionStatement(
|
||||
buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right)),
|
||||
),
|
||||
);
|
||||
|
||||
path.replaceWithMultiple(nodes);
|
||||
BinaryExpression(path) {
|
||||
const { node } = path;
|
||||
if (node.operator === operator) {
|
||||
path.replaceWith(build(node.left, node.right));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
visitor.AssignmentExpression = function(path, file) {
|
||||
const { node, scope } = path;
|
||||
if (!isAssignment(node)) return;
|
||||
|
||||
const nodes = [];
|
||||
const exploded = explode(node.left, nodes, file, scope);
|
||||
nodes.push(
|
||||
buildAssignment(exploded.ref, opts.build(exploded.uid, node.right)),
|
||||
);
|
||||
path.replaceWithMultiple(nodes);
|
||||
};
|
||||
|
||||
visitor.BinaryExpression = function(path) {
|
||||
const { node } = path;
|
||||
if (node.operator === opts.operator) {
|
||||
path.replaceWith(opts.build(node.left, node.right));
|
||||
}
|
||||
};
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "babel-helper-builder-react-jsx",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to build react jsx",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-builder-react-jsx",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-types": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.16",
|
||||
"esutils": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,6 @@ export default function(opts) {
|
||||
const callExpr = buildElementCall(path.get("openingElement"), file);
|
||||
|
||||
callExpr.arguments = callExpr.arguments.concat(path.node.children);
|
||||
|
||||
if (callExpr.arguments.length >= 3) {
|
||||
callExpr._prettyCall = true;
|
||||
}
|
||||
|
||||
path.replaceWith(t.inherits(callExpr, path.node));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel-helper-call-delegate",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to call delegate",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-call-delegate",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-hoist-variables": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-hoist-variables": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel-helper-define-map",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to define a map",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-define-map",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-function-name": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15",
|
||||
"babel-helper-function-name": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16",
|
||||
"lodash": "^4.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "babel-helper-explode-assignable-expression",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to explode an assignable expression",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-assignable-expression",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ function getObjRef(node, nodes, file, scope) {
|
||||
}
|
||||
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(temp, ref)]));
|
||||
scope.push({ id: temp });
|
||||
nodes.push(t.assignmentExpression("=", temp, ref));
|
||||
return temp;
|
||||
}
|
||||
|
||||
@@ -42,7 +43,8 @@ function getPropRef(node, nodes, file, scope) {
|
||||
if (t.isLiteral(key) && t.isPureish(key)) return key;
|
||||
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(temp, prop)]));
|
||||
scope.push({ id: temp });
|
||||
nodes.push(t.assignmentExpression("=", temp, prop));
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel-helper-explode-class",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to explode class",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-explode-class",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-bindify-decorators": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-bindify-decorators": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-helper-fixtures",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to support fixtures",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel-helper-function-name",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to change the property 'name' of every function",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-function-name",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-get-function-arity": "7.0.0-alpha.15",
|
||||
"babel-template": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-get-function-arity": "7.0.0-alpha.16",
|
||||
"babel-template": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ function wrap(state, method, id, scope) {
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
|
||||
}).expression;
|
||||
template.callee._skipModulesRemap = true;
|
||||
|
||||
// shim in dummy params to retain function arity, if you try to read the
|
||||
// source then you'll get the original since it's proxied so it's all good
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "babel-helper-get-function-arity",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to get function arity",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-get-function-arity",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "babel-helper-hoist-variables",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to hoist variables",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-hoist-variables",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "babel-helper-optimise-call-expression",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to optimise call expression",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-optimise-call-expression",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "babel-helper-plugin-test-runner",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to support test runner",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-plugin-test-runner",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.15"
|
||||
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "babel-helper-regex",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to check for literal RegEx",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-regex",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-types": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.16",
|
||||
"lodash": "^4.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel-helper-remap-async-to-generator",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to remap async functions to generators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-remap-async-to-generator",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-function-name": "7.0.0-alpha.15",
|
||||
"babel-template": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-wrap-function": "7.0.0-alpha.16",
|
||||
"babel-template": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
/* @noflow */
|
||||
|
||||
import type { NodePath } from "babel-traverse";
|
||||
import nameFunction from "babel-helper-function-name";
|
||||
import template from "babel-template";
|
||||
import wrapFunction from "babel-helper-wrap-function";
|
||||
import * as t from "babel-types";
|
||||
import rewriteForAwait from "./for-await";
|
||||
|
||||
const buildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
return function NAME(PARAMS) {
|
||||
return REF.apply(this, arguments);
|
||||
};
|
||||
})
|
||||
`);
|
||||
|
||||
const namedBuildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
function NAME(PARAMS) {
|
||||
return REF.apply(this, arguments);
|
||||
}
|
||||
return NAME;
|
||||
})
|
||||
`);
|
||||
|
||||
const awaitVisitor = {
|
||||
Function(path) {
|
||||
path.skip();
|
||||
@@ -71,123 +51,6 @@ const awaitVisitor = {
|
||||
},
|
||||
};
|
||||
|
||||
function classOrObjectMethod(path: NodePath, callId: Object) {
|
||||
const node = path.node;
|
||||
const body = node.body;
|
||||
|
||||
node.async = false;
|
||||
|
||||
const container = t.functionExpression(
|
||||
null,
|
||||
[],
|
||||
t.blockStatement(body.body),
|
||||
true,
|
||||
);
|
||||
body.body = [
|
||||
t.returnStatement(
|
||||
t.callExpression(t.callExpression(callId, [container]), []),
|
||||
),
|
||||
];
|
||||
|
||||
// Regardless of whether or not the wrapped function is a an async method
|
||||
// or generator the outer function should not be
|
||||
node.generator = false;
|
||||
|
||||
// Unwrap the wrapper IIFE's environment so super and this and such still work.
|
||||
path
|
||||
.get("body.body.0.argument.callee.arguments.0")
|
||||
.unwrapFunctionEnvironment();
|
||||
}
|
||||
|
||||
function plainFunction(path: NodePath, callId: Object) {
|
||||
const node = path.node;
|
||||
const isDeclaration = path.isFunctionDeclaration();
|
||||
const asyncFnId = node.id;
|
||||
let wrapper = buildWrapper;
|
||||
|
||||
if (path.isArrowFunctionExpression()) {
|
||||
path.arrowFunctionToExpression();
|
||||
} else if (!isDeclaration && asyncFnId) {
|
||||
wrapper = namedBuildWrapper;
|
||||
}
|
||||
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
node.id = null;
|
||||
|
||||
if (isDeclaration) {
|
||||
node.type = "FunctionExpression";
|
||||
}
|
||||
|
||||
const built = t.callExpression(callId, [node]);
|
||||
const container = wrapper({
|
||||
NAME: asyncFnId || null,
|
||||
REF: path.scope.generateUidIdentifier("ref"),
|
||||
FUNCTION: built,
|
||||
PARAMS: node.params.reduce(
|
||||
(acc, param) => {
|
||||
acc.done =
|
||||
acc.done || t.isAssignmentPattern(param) || t.isRestElement(param);
|
||||
|
||||
if (!acc.done) {
|
||||
acc.params.push(path.scope.generateUidIdentifier("x"));
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
params: [],
|
||||
done: false,
|
||||
},
|
||||
).params,
|
||||
}).expression;
|
||||
|
||||
if (isDeclaration) {
|
||||
const declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(
|
||||
t.identifier(asyncFnId.name),
|
||||
t.callExpression(container, []),
|
||||
),
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
|
||||
if (path.parentPath.isExportDefaultDeclaration()) {
|
||||
// change the path type so that replaceWith() does not wrap
|
||||
// the identifier into an expressionStatement
|
||||
path.parentPath.insertBefore(declar);
|
||||
path.parentPath.replaceWith(
|
||||
t.exportNamedDeclaration(null, [
|
||||
t.exportSpecifier(
|
||||
t.identifier(asyncFnId.name),
|
||||
t.identifier("default"),
|
||||
),
|
||||
]),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(declar);
|
||||
} else {
|
||||
const retFunction = container.body.body[1].argument;
|
||||
if (!asyncFnId) {
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
parent: path.parent,
|
||||
scope: path.scope,
|
||||
});
|
||||
}
|
||||
|
||||
if (!retFunction || retFunction.id || node.params.length) {
|
||||
// we have an inferred function id or params so we need this wrapper
|
||||
path.replaceWith(t.callExpression(container, []));
|
||||
} else {
|
||||
// we can omit this wrapper as the conditions it protects for do not apply
|
||||
path.replaceWith(built);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function(path: NodePath, file: Object, helpers: Object) {
|
||||
if (!helpers) {
|
||||
// bc for 6.15 and earlier
|
||||
@@ -199,9 +62,8 @@ export default function(path: NodePath, file: Object, helpers: Object) {
|
||||
wrapAwait: helpers.wrapAwait,
|
||||
});
|
||||
|
||||
if (path.isClassMethod() || path.isObjectMethod()) {
|
||||
classOrObjectMethod(path, helpers.wrapAsync);
|
||||
} else {
|
||||
plainFunction(path, helpers.wrapAsync);
|
||||
}
|
||||
path.node.async = false;
|
||||
path.node.generator = true;
|
||||
|
||||
wrapFunction(path, helpers.wrapAsync);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "babel-helper-replace-supers",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper function to replace supers",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-optimise-call-expression": "7.0.0-alpha.15",
|
||||
"babel-messages": "7.0.0-alpha.15",
|
||||
"babel-template": "7.0.0-alpha.15",
|
||||
"babel-traverse": "7.0.0-alpha.15",
|
||||
"babel-types": "7.0.0-alpha.15"
|
||||
"babel-helper-optimise-call-expression": "7.0.0-alpha.16",
|
||||
"babel-messages": "7.0.0-alpha.16",
|
||||
"babel-template": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as messages from "babel-messages";
|
||||
import * as t from "babel-types";
|
||||
|
||||
// ✌️
|
||||
const HARDCORE_THIS_REF = Symbol();
|
||||
const HARDCORE_THIS_REF = new WeakSet();
|
||||
|
||||
function isIllegalBareSuper(node, parent) {
|
||||
if (!t.isSuper(node)) return false;
|
||||
@@ -57,7 +57,7 @@ const visitor = {
|
||||
},
|
||||
|
||||
ThisExpression(path, state) {
|
||||
if (!path.node[HARDCORE_THIS_REF]) {
|
||||
if (!HARDCORE_THIS_REF.has(path.node)) {
|
||||
state.thises.push(path);
|
||||
}
|
||||
},
|
||||
@@ -309,7 +309,7 @@ export default class ReplaceSupers {
|
||||
|
||||
optimiseCall(callee, args) {
|
||||
const thisNode = t.thisExpression();
|
||||
thisNode[HARDCORE_THIS_REF] = true;
|
||||
HARDCORE_THIS_REF.add(thisNode);
|
||||
return optimiseCall(callee, thisNode, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-helper-transform-fixture-test-runner",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Transform test runner for babel-helper-fixtures module",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,11 +8,11 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-transform-fixture-test-runner",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-code-frame": "7.0.0-alpha.15",
|
||||
"babel-core": "7.0.0-alpha.15",
|
||||
"babel-helper-fixtures": "7.0.0-alpha.15",
|
||||
"babel-polyfill": "7.0.0-alpha.15",
|
||||
"chai": "^3.0.0",
|
||||
"babel-code-frame": "7.0.0-alpha.16",
|
||||
"babel-core": "7.0.0-alpha.16",
|
||||
"babel-helper-fixtures": "7.0.0-alpha.16",
|
||||
"babel-polyfill": "7.0.0-alpha.16",
|
||||
"chai": "^4.1.0",
|
||||
"lodash": "^4.2.0",
|
||||
"resolve": "^1.3.2",
|
||||
"source-map": "^0.5.0"
|
||||
|
||||
@@ -18,7 +18,6 @@ import vm from "vm";
|
||||
const moduleCache = {};
|
||||
const testContext = vm.createContext({
|
||||
...helpers,
|
||||
assert: chai.assert,
|
||||
process: process,
|
||||
transform: babel.transform,
|
||||
setTimeout: setTimeout,
|
||||
@@ -26,6 +25,17 @@ const testContext = vm.createContext({
|
||||
});
|
||||
testContext.global = testContext;
|
||||
|
||||
// Add chai's assert to the global context
|
||||
// It has to be required inside the testContext as otherwise some assertions do not
|
||||
// work as chai would reference globals (RegExp, Array, ...) from this context
|
||||
vm.runInContext(
|
||||
"(function(require) { global.assert=require('chai').assert; });",
|
||||
testContext,
|
||||
{
|
||||
displayErrors: true,
|
||||
},
|
||||
)(id => runModuleInTestContext(id, __filename));
|
||||
|
||||
// Initialize the test context with the polyfill, and then freeze the global to prevent implicit
|
||||
// global creation in tests, which could cause things to bleed between tests.
|
||||
runModuleInTestContext("babel-polyfill", __filename);
|
||||
|
||||
3
packages/babel-helper-wrap-function/.npmignore
Normal file
3
packages/babel-helper-wrap-function/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
27
packages/babel-helper-wrap-function/README.md
Normal file
27
packages/babel-helper-wrap-function/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# babel-helper-wrap-function
|
||||
|
||||
This helper wraps a function within a call expression. It works with any function: statements, expressions and methods; both named and anonymous.
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```js
|
||||
(function () {
|
||||
}());
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
_wrapper(function () {
|
||||
})();
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import wrapFunction from "babel-helper-wrap-function";
|
||||
|
||||
wrapFunction(nodePathOfTheFunction, nodeWhichReferencesToTheWrapper);
|
||||
```
|
||||
14
packages/babel-helper-wrap-function/package.json
Normal file
14
packages/babel-helper-wrap-function/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "babel-helper-wrap-function",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Helper to wrap functions inside a function call.",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-wrap-function",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-helper-function-name": "7.0.0-alpha.16",
|
||||
"babel-template": "7.0.0-alpha.16",
|
||||
"babel-traverse": "7.0.0-alpha.16",
|
||||
"babel-types": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
146
packages/babel-helper-wrap-function/src/index.js
Normal file
146
packages/babel-helper-wrap-function/src/index.js
Normal file
@@ -0,0 +1,146 @@
|
||||
/* @flow */
|
||||
|
||||
import type { NodePath } from "babel-traverse";
|
||||
import nameFunction from "babel-helper-function-name";
|
||||
import template from "babel-template";
|
||||
import * as t from "babel-types";
|
||||
|
||||
const buildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
return function NAME(PARAMS) {
|
||||
return REF.apply(this, arguments);
|
||||
};
|
||||
})
|
||||
`);
|
||||
|
||||
const namedBuildWrapper = template(`
|
||||
(() => {
|
||||
var REF = FUNCTION;
|
||||
function NAME(PARAMS) {
|
||||
return REF.apply(this, arguments);
|
||||
}
|
||||
return NAME;
|
||||
})
|
||||
`);
|
||||
|
||||
function classOrObjectMethod(path: NodePath, callId: Object) {
|
||||
const node = path.node;
|
||||
const body = node.body;
|
||||
|
||||
const container = t.functionExpression(
|
||||
null,
|
||||
[],
|
||||
t.blockStatement(body.body),
|
||||
true,
|
||||
);
|
||||
body.body = [
|
||||
t.returnStatement(
|
||||
t.callExpression(t.callExpression(callId, [container]), []),
|
||||
),
|
||||
];
|
||||
|
||||
// Regardless of whether or not the wrapped function is a an async method
|
||||
// or generator the outer function should not be
|
||||
node.async = false;
|
||||
node.generator = false;
|
||||
|
||||
// Unwrap the wrapper IIFE's environment so super and this and such still work.
|
||||
path
|
||||
.get("body.body.0.argument.callee.arguments.0")
|
||||
.unwrapFunctionEnvironment();
|
||||
}
|
||||
|
||||
function plainFunction(path: NodePath, callId: Object) {
|
||||
const node = path.node;
|
||||
const isDeclaration = path.isFunctionDeclaration();
|
||||
const functionId = node.id;
|
||||
let wrapper = buildWrapper;
|
||||
|
||||
if (path.isArrowFunctionExpression()) {
|
||||
path.arrowFunctionToExpression();
|
||||
} else if (!isDeclaration && functionId) {
|
||||
wrapper = namedBuildWrapper;
|
||||
}
|
||||
|
||||
node.id = null;
|
||||
|
||||
if (isDeclaration) {
|
||||
node.type = "FunctionExpression";
|
||||
}
|
||||
|
||||
const built = t.callExpression(callId, [node]);
|
||||
const container = wrapper({
|
||||
NAME: functionId || null,
|
||||
REF: path.scope.generateUidIdentifier("ref"),
|
||||
FUNCTION: built,
|
||||
PARAMS: node.params.reduce(
|
||||
(acc, param) => {
|
||||
acc.done =
|
||||
acc.done || t.isAssignmentPattern(param) || t.isRestElement(param);
|
||||
|
||||
if (!acc.done) {
|
||||
acc.params.push(path.scope.generateUidIdentifier("x"));
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
params: [],
|
||||
done: false,
|
||||
},
|
||||
).params,
|
||||
}).expression;
|
||||
|
||||
if (isDeclaration && functionId) {
|
||||
const declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(
|
||||
t.identifier(functionId.name),
|
||||
t.callExpression(container, []),
|
||||
),
|
||||
]);
|
||||
(declar: any)._blockHoist = true;
|
||||
|
||||
if (path.parentPath.isExportDefaultDeclaration()) {
|
||||
// change the path type so that replaceWith() does not wrap
|
||||
// the identifier into an expressionStatement
|
||||
path.parentPath.insertBefore(declar);
|
||||
path.parentPath.replaceWith(
|
||||
t.exportNamedDeclaration(null, [
|
||||
t.exportSpecifier(
|
||||
t.identifier(functionId.name),
|
||||
t.identifier("default"),
|
||||
),
|
||||
]),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(declar);
|
||||
} else {
|
||||
const retFunction = container.body.body[1].argument;
|
||||
if (!functionId) {
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
parent: path.parent,
|
||||
scope: path.scope,
|
||||
});
|
||||
}
|
||||
|
||||
if (!retFunction || retFunction.id || node.params.length) {
|
||||
// we have an inferred function id or params so we need this wrapper
|
||||
path.replaceWith(t.callExpression(container, []));
|
||||
} else {
|
||||
// we can omit this wrapper as the conditions it protects for do not apply
|
||||
path.replaceWith(built);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function wrapFunction(path: NodePath, callId: Object) {
|
||||
if (path.isClassMethod() || path.isObjectMethod()) {
|
||||
classOrObjectMethod(path, callId);
|
||||
} else {
|
||||
plainFunction(path, callId);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-helpers",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Collection of helper functions used by Babel transforms.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
@@ -8,6 +8,6 @@
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helpers",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"babel-template": "7.0.0-alpha.15"
|
||||
"babel-template": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ helpers.get = template(`
|
||||
helpers.inherits = template(`
|
||||
(function (subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
throw new TypeError("Super expression must either be null or a function");
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
@@ -432,13 +432,29 @@ helpers.objectDestructuringEmpty = template(`
|
||||
`);
|
||||
|
||||
helpers.objectWithoutProperties = template(`
|
||||
(function (obj, keys) {
|
||||
(function (source, excluded) {
|
||||
if (source == null) return {};
|
||||
|
||||
var target = {};
|
||||
for (var i in obj) {
|
||||
if (keys.indexOf(i) >= 0) continue;
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
||||
target[i] = obj[i];
|
||||
var sourceKeys = Object.keys(source);
|
||||
var key, i;
|
||||
|
||||
for (i = 0; i < sourceKeys.length; i++) {
|
||||
key = sourceKeys[i];
|
||||
if (excluded.indexOf(key) >= 0) continue;
|
||||
target[key] = source[key];
|
||||
}
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
||||
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
||||
key = sourceSymbolKeys[i];
|
||||
if (excluded.indexOf(key) >= 0) continue;
|
||||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
})
|
||||
`);
|
||||
@@ -594,3 +610,23 @@ helpers.toConsumableArray = template(`
|
||||
}
|
||||
});
|
||||
`);
|
||||
|
||||
helpers.skipFirstGeneratorNext = template(`
|
||||
(function (fn) {
|
||||
return function () {
|
||||
var it = fn.apply(this, arguments);
|
||||
it.next();
|
||||
return it;
|
||||
}
|
||||
});
|
||||
`);
|
||||
|
||||
helpers.toPropertyKey = template(`
|
||||
(function (key) {
|
||||
if (typeof key === "symbol") {
|
||||
return key;
|
||||
} else {
|
||||
return String(key);
|
||||
}
|
||||
});
|
||||
`);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-messages",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Collection of debug messages used by Babel.",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-check-es2015-constants",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Compile ES2015 constants to ES5",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-check-es2015-constants",
|
||||
"license": "MIT",
|
||||
@@ -9,6 +9,6 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"devDependencies": {
|
||||
"babel-helper-plugin-test-runner": "7.0.0-alpha.15"
|
||||
"babel-helper-plugin-test-runner": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
export default function({ messages }) {
|
||||
export default function({ messages, types: t }) {
|
||||
/**
|
||||
* Helper function to run a statement before an expression by replacing it with a comma expression
|
||||
* and wrapping the statement in an IIFE as the first operand.
|
||||
*/
|
||||
function statementBeforeExpression(statement, expression) {
|
||||
return t.sequenceExpression([
|
||||
t.callExpression(
|
||||
t.functionExpression(null, [], t.blockStatement([statement])),
|
||||
[],
|
||||
),
|
||||
expression,
|
||||
]);
|
||||
}
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
Scope({ scope }) {
|
||||
@@ -7,7 +21,29 @@ export default function({ messages }) {
|
||||
if (binding.kind !== "const" && binding.kind !== "module") continue;
|
||||
|
||||
for (const violation of (binding.constantViolations: Array)) {
|
||||
throw violation.buildCodeFrameError(messages.get("readOnly", name));
|
||||
const throwNode = t.throwStatement(
|
||||
t.newExpression(t.identifier("Error"), [
|
||||
t.stringLiteral(messages.get("readOnly", name)),
|
||||
]),
|
||||
);
|
||||
|
||||
if (violation.isAssignmentExpression()) {
|
||||
violation
|
||||
.get("right")
|
||||
.replaceWith(
|
||||
statementBeforeExpression(
|
||||
throwNode,
|
||||
violation.get("right").node,
|
||||
),
|
||||
);
|
||||
} else if (violation.parentPath.isUpdateExpression()) {
|
||||
violation.parentPath.replaceWith(
|
||||
statementBeforeExpression(throwNode, violation.parent),
|
||||
);
|
||||
} else if (violation.parentPath.isForXStatement()) {
|
||||
violation.parentPath.ensureBlock();
|
||||
violation.parentPath.node.body.body.unshift(throwNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
(function(){
|
||||
const a = "foo";
|
||||
|
||||
if (false) a = "false";
|
||||
|
||||
return a;
|
||||
})();
|
||||
@@ -0,0 +1,9 @@
|
||||
function f() {
|
||||
const a = "foo";
|
||||
|
||||
if (false) a = "false";
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
assert.equal(f(), "foo", 'Const violation in not taken branch should be ignored.')
|
||||
@@ -0,0 +1,7 @@
|
||||
(function () {
|
||||
var a = "foo";
|
||||
if (false) a = (function () {
|
||||
throw new Error("\"a\" is read-only");
|
||||
}(), "false");
|
||||
return a;
|
||||
})();
|
||||
@@ -0,0 +1,14 @@
|
||||
assert.throws(function() {
|
||||
const [a, b] = [1, 2];
|
||||
a = 3;
|
||||
}, '"a" is read-only')
|
||||
|
||||
assert.throws(function() {
|
||||
const a = 1;
|
||||
[a] = [2];
|
||||
}, '"a" is read-only');
|
||||
|
||||
assert.throws(function() {
|
||||
const b = 1;
|
||||
({b} = {b: 2});
|
||||
}, '"b" is read-only');
|
||||
@@ -0,0 +1,5 @@
|
||||
var a = 1,
|
||||
b = 2;
|
||||
a = (function () {
|
||||
throw new Error("\"a\" is read-only");
|
||||
}(), 3);
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "\"a\" is read-only"
|
||||
}
|
||||
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/loop/exec.js
vendored
Normal file
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/loop/exec.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
assert.throws(function() {
|
||||
for (const i = 0; i < 3; i = i + 1) {
|
||||
// whatever
|
||||
}
|
||||
}, '"i" is read-only');
|
||||
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/loop/expected.js
vendored
Normal file
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/loop/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
for (var i = 0; i < 3; i = (function () {
|
||||
throw new Error("\"i\" is read-only");
|
||||
}(), i + 1)) {
|
||||
console.log(i);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "\"i\" is read-only"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const c = 17;
|
||||
let a = 0;
|
||||
|
||||
function f() {
|
||||
return ++c+--a;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
assert.throws(function() {
|
||||
const c = 17;
|
||||
let a = 0;
|
||||
|
||||
function f() {
|
||||
return ++c+--a;
|
||||
}
|
||||
|
||||
f();
|
||||
|
||||
}, '"c" is read-only');
|
||||
@@ -0,0 +1,8 @@
|
||||
var c = 17;
|
||||
var a = 0;
|
||||
|
||||
function f() {
|
||||
return (function () {
|
||||
throw new Error("\"c\" is read-only");
|
||||
}(), ++c) + --a;
|
||||
}
|
||||
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-assignment/exec.js
vendored
Normal file
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-assignment/exec.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
assert.throws(function() {
|
||||
const a = 3;
|
||||
a = 7;
|
||||
}, '"a" is read-only');
|
||||
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-assignment/expected.js
vendored
Normal file
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-assignment/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var MULTIPLIER = 5;
|
||||
MULTIPLIER = (function () {
|
||||
throw new Error("\"MULTIPLIER\" is read-only");
|
||||
}(), "overwrite");
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "\"MULTIPLIER\" is read-only"
|
||||
}
|
||||
12
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-for-in/exec.js
vendored
Normal file
12
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-for-in/exec.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
function f(arr) {
|
||||
const MULTIPLIER = 5;
|
||||
for (MULTIPLIER in arr);
|
||||
|
||||
return 'survived';
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
f([1,2,3]);
|
||||
}, '"MULTIPLIER" is read-only');
|
||||
|
||||
assert.equal(f([]), 'survived', 'For-in over empty array should not throw.');
|
||||
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-for-in/expected.js
vendored
Normal file
5
packages/babel-plugin-check-es2015-constants/test/fixtures/general/no-for-in/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var MULTIPLIER = 5;
|
||||
|
||||
for (MULTIPLIER in arr) {
|
||||
throw new Error("\"MULTIPLIER\" is read-only");
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "\"MULTIPLIER\" is read-only"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
const a = "str";
|
||||
--a;
|
||||
@@ -0,0 +1,4 @@
|
||||
assert.throws(function() {
|
||||
const a = "str";
|
||||
--a;
|
||||
}, '"a" is read-only');
|
||||
@@ -0,0 +1,4 @@
|
||||
var a = "str";
|
||||
(function () {
|
||||
throw new Error("\"a\" is read-only");
|
||||
})(), --a;
|
||||
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/update-expression/exec.js
vendored
Normal file
4
packages/babel-plugin-check-es2015-constants/test/fixtures/general/update-expression/exec.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
assert.throws(function() {
|
||||
const foo = 1;
|
||||
foo++;
|
||||
}, '"foo" is read-only');
|
||||
@@ -1,4 +1,4 @@
|
||||
var foo = 1;
|
||||
(function () {
|
||||
throw new TypeError("\"foo\" is read-only");
|
||||
})();
|
||||
throw new Error("\"foo\" is read-only");
|
||||
})(), foo++;
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "\"foo\" is read-only"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-external-helpers",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "This plugin contains helper functions that’ll be placed at the top of the generated code",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-external-helpers",
|
||||
"license": "MIT",
|
||||
@@ -9,6 +9,6 @@
|
||||
"babel-plugin"
|
||||
],
|
||||
"devDependencies": {
|
||||
"babel-helper-plugin-test-runner": "7.0.0-alpha.15"
|
||||
"babel-helper-plugin-test-runner": "7.0.0-alpha.16"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-async-functions",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of async functions",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-functions",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-async-generators",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of async generator functions",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-async-generators",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-class-properties",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of class properties",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-class-properties",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-decorators",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of decorators",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-decorators",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-do-expressions",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of do expressions",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-do-expressions",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-dynamic-import",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of import()",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-exponentiation-operator",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of the exponentiation operator",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-exponentation-operator",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-export-extensions",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of export extensions",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-export-extensions",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-flow",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of the flow syntax",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-flow",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "babel-plugin-syntax-function-bind",
|
||||
"version": "7.0.0-alpha.15",
|
||||
"version": "7.0.0-alpha.16",
|
||||
"description": "Allow parsing of function bind",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-function-bind",
|
||||
"license": "MIT",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user