Compare commits

..

42 Commits

Author SHA1 Message Date
Henry Zhu
7f1cd44d60 v7.0.0-alpha.16 2017-07-25 17:35:35 -04:00
Henry Zhu
2841945095 temporarily rename function-sent pkg to 2 (#6011) [skip ci]
* update readme [skip ci]

* rename to sent2 until we get the package [skip ci]
2017-07-25 17:30:31 -04:00
Henry Zhu
76060bb2c7 commit yarn.lock 2017-07-25 17:10:10 -04:00
Henry Zhu
84dfa659e7 update to alpha.15 (#6009) 2017-07-25 17:08:15 -04:00
Samuel Reed
e0b4543601 feature: Support whitelisting mutable props for react-constant-elements (#5307) 2017-07-25 13:34:21 -05:00
Andy
248743e6c5 babel-types: Add TypeScript definitions (#5856)
* babel-types: Add TypeScript definitions

* Add missing builders

* Allow arrow function to have "generator"

* Replace link to resolved issue with comment

* Re-add 'generator' to functionCommon
2017-07-25 11:42:25 -04:00
Brian Ng
9a1b8ea443 Add support for flow predicates in babel-generator (#5984) 2017-07-25 11:38:17 -04:00
Brian Ng
55aea26f13 Add support for export type star in babel-generator (#5985)
* Add support for export type star in babel-generator

* Bump babylon
2017-07-25 11:37:27 -04:00
Nicolò Ribaudo
fb9a752262 Function sent (#5920)
* Create "babel-helper-wrap-function"

It contains the logic to wrap a function inside a call expression.
It was part of the "babel-helper-remap-async-to-generator" package, but
it is needed to transpile "function.sent"

* Create "babel-transform-function-sent"

It transforms the "function.sent" meta property by replacing it with
"yield" and making the generator ignore the first ".next()" call.

* "function.sent" is the last value passed to .next(), not the first one

* Disable exec tests on old node

* Fix flow error

* Add "transform-function-sent" to "stage-2" preset

* Do every trasformation in one traversal

* Test for "yield function.sent"

* [skip ci]

* Fix some typos [skip ci]
2017-07-25 11:07:01 -04:00
Peeyush Kushwaha
4a35243118 Non string computed keys in object-rest-spread (#5757) 2017-07-25 09:46:52 -05:00
MarckK
9fc910d8c0 Add optionality to catch bindings (#5956) 2017-07-25 09:38:48 -05:00
Noah Lemen
51a293601b add JSXAttribute visitor function, wraps JSXElement attributes in a JSXExpressionContainer; also adds test fixtures (#6006) 2017-07-25 09:30:32 -04:00
Daniel Tschinder
19c4dd2d8c Update chai to 4.x (#6002) 2017-07-24 15:19:32 -04:00
Peeyush Kushwaha
2225892348 Use first binding for multiple var declarations (#5745)
* Use first binding for multiple var declarations
Since var declarations after initial binding have no effect, use the
first declaration. Fixes #2378

* Include hoisted function bindings

* Missing newline in expected.js

* Simplify constantViolations in new Binding on existing

* clarify comment language
2017-07-24 14:43:17 -04:00
Daniel Tschinder
677160385c Update chalk to 2.x (#6003) 2017-07-24 11:06:57 -04:00
Daniel Tschinder
9b04cbbc4f Update find-cache-dir to 1.0 (#5999) 2017-07-23 20:23:55 -04:00
Daniel Tschinder
4aca487b6d Update default-require-extensions to 2.0 (#6000) 2017-07-23 20:23:29 -04:00
Daniel Tschinder
5afe40b095 Update to-fast-properties to 2.0 (#5997) 2017-07-23 09:22:05 -04:00
Daniel Tschinder
b081f68e87 Update output-file-sync to 2.0 (#5996)
* Update output-file-sync to 2.0

* Ignore test tmp directory
2017-07-23 09:21:51 -04:00
Daniel Tschinder
c9ed159a18 Update jsesc to the latest version (#5995) 2017-07-23 09:21:22 -04:00
Daniel Tschinder
b9ed9919c1 Update globals to v10 (#5993) 2017-07-23 09:21:08 -04:00
Daniel Tschinder
04b4e414ad Fix clean to remove package-lock files (#5991)
Otherweise the same versions get installed over an over again in
dev environments
2017-07-23 09:20:36 -04:00
Ryan Gaus
0b890ced19 Code generator tests (#5847) 2017-07-20 18:22:18 -04:00
Justin Ridgewell
c60bf9a897 Fixup builder-binary-assignment-operator-visitor (#5969)
Using a `SequenceExpression` instead, we avoid awkward
`AssignmentExpression`s as direct children of `BlockStatement`s.
2017-07-20 11:47:47 -04:00
Naveen jain
245c78dcdc Added test cases for babel-generator (#5934)
* edited .gitignore to ignore all package-lock.json files
2017-07-20 11:39:26 -04:00
Justin Ridgewell
8a98141b60 Fix a few type inferences (#5835) 2017-07-20 11:38:12 -04:00
Justin Ridgewell
78544417fc Remove noop (#5970)
It’s ugly, but it gets the job done. And it unblocks my babel-type
changes.
2017-07-20 11:36:13 -04:00
Justin Ridgewell
c6edce115c Fix numeric-separator transform (#5968) 2017-07-20 11:35:53 -04:00
Selwyn
579499c66d Update v8flags to version 3.0.0 (#5975) 2017-07-19 14:31:23 -04:00
Justin Ridgewell
827c70e015 Support exporting deep destructuring (#5953) 2017-07-18 14:07:09 -05:00
Justin Ridgewell
8a5488e59f Fix for-of loose optimization (#5964)
VariableDeclarators can’t have a MemberExpression id.
2017-07-18 15:01:36 -04:00
Justin Ridgewell
63204ae51e Remove maybePopFromStatements (#5945)
It prevented you from pushing into the `params` of a function.

```js
fnpath.pushContainer("params", t.identifier("memo"))
```
2017-07-18 14:55:33 -04:00
Justin Ridgewell
28ae47a174 Stop mutating nodes (#5963)
* Stop mutating nodes

* Update tests

* linting
2017-07-18 13:24:07 -04:00
Mauro Bringolf
aa684d1b0c Spec compliancy of check-es2015-constants plugin (#5930)
* Figuring out where to place throw statement

* Restored path argument destructuring

* New approach using comma expressions for assignments

* Moved throwNode into body of forXstatements

* Refactored with helper function and ensureBlock, additional tests for update exprs

* Added exec tests for all violations

* Hoisted helper function for comma expression outside of visitor
2017-07-17 20:01:01 -04:00
Brian Ng
1fdec955f8 Bump istanbul and nyc (#5959) 2017-07-17 15:58:49 -04:00
Sarup Banskota
213ad1ed7a [generator] remove parens from break & continue (#5950)
* Remove parens around break and continue

Fixes #5742

* Fix space in doc comment

* Add some tests

* Remove newlines within CommentBlock

* Prevent newline before/after label

* Remove reference to node

* Check for label within startTerminatorless

* Print block instead of single line comment

* Clean up
2017-07-17 09:30:28 -07:00
Justin Ridgewell
797fb3c2e4 Optimize and remove state from typeof-symbol transform (#5955)
Also fixes a bug with returning a Symbol from a Class constructor
(because the transform wasn’t run on helpers before).
2017-07-17 10:51:36 -04:00
Justin Ridgewell
9d612e717e Fix react-inline-elements bug (#5958) 2017-07-17 10:46:13 -04:00
Justin Ridgewell
e919c6e6eb Add several test cases for systemjs exports (#5954) 2017-07-17 08:51:37 -05:00
Sven SAULEAU
d82afb407e Merge pull request #5949 from babel/unused-eslint-rule
remove unused ESLint rule
2017-07-14 11:51:36 +02:00
Sven SAULEAU
b858d7ce5e chore: remove unused ESLint rule 2017-07-14 11:25:09 +02:00
Mauro Bringolf
b83e0ec7b0 2nd try: Add loose option for es2015-parameters transformation (#5943)
* Import changes to parameters package from previous branch

* Refactor plugin option access via state
2017-07-12 17:36:44 -04:00
389 changed files with 5385 additions and 2065 deletions

1
.gitignore vendored
View File

@@ -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

View File

@@ -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:

View File

@@ -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": {

View File

@@ -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",

View File

@@ -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",

View File

@@ -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"
}
}

View File

@@ -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,

View File

@@ -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"
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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"
}
}

View File

@@ -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(")");
}

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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");

View File

@@ -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);
}

View File

@@ -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>) {

View File

@@ -22,3 +22,5 @@ declare module B {
declare export type B = {};
declare export interface Moon {}
}
declare module "foo" { declare export type * from "bar"; }

View File

@@ -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";
}

View 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;

View 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;

View File

@@ -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";

View File

@@ -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";

View 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;
}

View 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;
}

View File

@@ -11,3 +11,4 @@ false;
0o70;
0X1F;
-0b1111011;
"use strict";

View File

@@ -11,3 +11,4 @@ false;
0o70;
0X1F;
-0b1111011;
"use strict";

View File

@@ -1,2 +1,4 @@
foo ||bar;
(x => x)|| bar;
(function a(x){return x;})|| 2;
0||(function(){return alpha;});

View File

@@ -1,2 +1,10 @@
foo || bar;
(x => x) || bar;
(function a(x) {
return x;
}) || 2;
0 || function () {
return alpha;
};

View 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 {}

View 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 {}

View File

@@ -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",

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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;
}

View File

@@ -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"
}
}

View File

@@ -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));
},
};

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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;
}

View File

@@ -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"
}
}

View File

@@ -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",

View File

@@ -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"
}
}

View File

@@ -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

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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);
}

View File

@@ -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"
}
}

View File

@@ -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);
}
}

View File

@@ -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"

View File

@@ -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);

View File

@@ -0,0 +1,3 @@
src
test
*.log

View 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);
```

View 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"
}
}

View 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);
}
}

View File

@@ -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"
}
}

View File

@@ -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);
}
});
`);

View File

@@ -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/",

View File

@@ -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"
}
}

View File

@@ -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);
}
}
}
},

View File

@@ -0,0 +1,7 @@
(function(){
const a = "foo";
if (false) a = "false";
return a;
})();

View File

@@ -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.')

View File

@@ -0,0 +1,7 @@
(function () {
var a = "foo";
if (false) a = (function () {
throw new Error("\"a\" is read-only");
}(), "false");
return a;
})();

View File

@@ -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');

View File

@@ -0,0 +1,5 @@
var a = 1,
b = 2;
a = (function () {
throw new Error("\"a\" is read-only");
}(), 3);

View File

@@ -1,3 +0,0 @@
{
"throws": "\"a\" is read-only"
}

View File

@@ -0,0 +1,5 @@
assert.throws(function() {
for (const i = 0; i < 3; i = i + 1) {
// whatever
}
}, '"i" is read-only');

View 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);
}

View File

@@ -1,3 +0,0 @@
{
"throws": "\"i\" is read-only"
}

View File

@@ -0,0 +1,6 @@
const c = 17;
let a = 0;
function f() {
return ++c+--a;
}

View File

@@ -0,0 +1,11 @@
assert.throws(function() {
const c = 17;
let a = 0;
function f() {
return ++c+--a;
}
f();
}, '"c" is read-only');

View File

@@ -0,0 +1,8 @@
var c = 17;
var a = 0;
function f() {
return (function () {
throw new Error("\"c\" is read-only");
}(), ++c) + --a;
}

View File

@@ -0,0 +1,4 @@
assert.throws(function() {
const a = 3;
a = 7;
}, '"a" is read-only');

View File

@@ -0,0 +1,4 @@
var MULTIPLIER = 5;
MULTIPLIER = (function () {
throw new Error("\"MULTIPLIER\" is read-only");
}(), "overwrite");

View File

@@ -1,3 +0,0 @@
{
"throws": "\"MULTIPLIER\" is read-only"
}

View 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.');

View File

@@ -0,0 +1,5 @@
var MULTIPLIER = 5;
for (MULTIPLIER in arr) {
throw new Error("\"MULTIPLIER\" is read-only");
}

View File

@@ -1,3 +0,0 @@
{
"throws": "\"MULTIPLIER\" is read-only"
}

View File

@@ -0,0 +1,2 @@
const a = "str";
--a;

View File

@@ -0,0 +1,4 @@
assert.throws(function() {
const a = "str";
--a;
}, '"a" is read-only');

View File

@@ -0,0 +1,4 @@
var a = "str";
(function () {
throw new Error("\"a\" is read-only");
})(), --a;

View File

@@ -0,0 +1,4 @@
assert.throws(function() {
const foo = 1;
foo++;
}, '"foo" is read-only');

View File

@@ -1,4 +1,4 @@
var foo = 1;
(function () {
throw new TypeError("\"foo\" is read-only");
})();
throw new Error("\"foo\" is read-only");
})(), foo++;

View File

@@ -1,3 +0,0 @@
{
"throws": "\"foo\" is read-only"
}

View File

@@ -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 thatll 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"
}
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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