Skip to content

Commit

Permalink
Merge branch 'master' into next-8-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 20, 2020
2 parents 27dd8f0 + 1a08aa5 commit f834534
Show file tree
Hide file tree
Showing 77 changed files with 1,544 additions and 391 deletions.
17 changes: 5 additions & 12 deletions CONTRIBUTING.md
Expand Up @@ -16,9 +16,7 @@

# Contributing

Contributions are always welcome, no matter how large or small. Before
contributing, please read the
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
Contributions are always welcome, no matter how large or small! Before contributing, please read the [code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).

## Not sure where to start?

Expand All @@ -39,12 +37,9 @@ Feel free to check out the `#discussion`/`#development` channels on our [Slack](

## Developing

**Note:** Versions `< 5.1.10` can't be built.
*Node*: Check that Node is [installed](https://nodejs.org/en/download/) with version 10 and up. You can check this with `node -v`.

Babel is built for Node 6 and up but we develop using Node 8 and yarn. You can check this with `node -v`.

Make sure that Yarn is installed with version >= `0.28.0`.
Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
*Yarn*: Make sure that Yarn 1 is [installed](https://classic.yarnpkg.com/en/docs/install) with version >= `1.19.0`.

### Setup

Expand Down Expand Up @@ -72,7 +67,7 @@ $ make watch

to have Babel build itself and incrementally build files on change.

You can access the built files for individual packages from `packages/<package-name>/lib`.
> You can access the built files for individual packages from `packages/<package-name>/lib`.
If you wish to build a copy of Babel for distribution, then run:

Expand Down Expand Up @@ -109,9 +104,7 @@ If you just want to run all tests:
$ make test-only
```

Most likely you'll want to focus in on a specific issue.

To run tests for a specific package in [packages](https://github.com/babel/babel/tree/master/packages), you can use the `TEST_ONLY` environment variable:
When working on an issue, you will most likely want to focus on a particular [packages](https://github.com/babel/babel/tree/master/packages). Using `TEST_ONLY` will only run tests for that specific package.

```sh
$ TEST_ONLY=babel-cli make test
Expand Down
13 changes: 0 additions & 13 deletions Gulpfile.js
Expand Up @@ -227,19 +227,6 @@ gulp.task("build-rollup", () => buildRollup(libBundles));
gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle));

gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles));
gulp.task("build-babel-types-deps", () =>
buildBabel(
/* exclude */ libBundles,
"packages/babel-helper-validator-identifier/src/**/*.js"
)
);
gulp.task("build-babel-types-self", () =>
buildBabel(/* exclude */ libBundles, "packages/babel-types/src/**/*.js")
);
gulp.task(
"build-babel-types",
gulp.series("build-babel-types-deps", "build-babel-types-self")
);
gulp.task("build", gulp.parallel("build-rollup", "build-babel"));

gulp.task("default", gulp.series("build"));
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Expand Up @@ -78,6 +78,9 @@ build-no-bundle: clean clean-lib
$(MAKE) generate-type-helpers
$(MAKE) build-typings

build-no-bundle-ci: bootstrap-only
$(MAKE) build-no-bundle

watch: build-no-bundle
BABEL_ENV=development $(YARN) gulp watch

Expand All @@ -91,9 +94,7 @@ code-quality: flow lint
flow:
$(YARN) flow check --strip-root

bootstrap-flowcheck: bootstrap-only
$(YARN) gulp build-babel-types
$(MAKE) build-typings
bootstrap-flowcheck: build-no-bundle-ci

lint-ci: lint-js-ci lint-ts-ci check-compat-data-ci

Expand All @@ -103,7 +104,7 @@ lint-js-ci: bootstrap-only
lint-ts-ci: bootstrap-flowcheck
$(MAKE) lint-ts

check-compat-data-ci: bootstrap-only
check-compat-data-ci: build-no-bundle-ci
$(MAKE) check-compat-data

lint: lint-js lint-ts
Expand Down
5 changes: 1 addition & 4 deletions babel.config.js
Expand Up @@ -8,6 +8,7 @@ module.exports = function(api) {
const envOptsNoTargets = {
loose: true,
modules: false,
shippedProposals: true,
exclude: ["transform-typeof-symbol"],
};
const envOpts = Object.assign({}, envOptsNoTargets);
Expand Down Expand Up @@ -100,14 +101,10 @@ module.exports = function(api) {
"@babel/plugin-transform-flow-strip-types",
["@babel/proposal-class-properties", { loose: true }],
"@babel/proposal-export-namespace-from",
"@babel/proposal-numeric-separator",
[
"@babel/proposal-object-rest-spread",
{ useBuiltIns: true, loose: true },
],
["@babel/plugin-proposal-optional-chaining", { loose: true }],
["@babel/plugin-proposal-nullish-coalescing-operator", { loose: true }],

compileDynamicImport ? dynamicImportUrlToPath : null,
compileDynamicImport ? "@babel/plugin-proposal-dynamic-import" : null,

Expand Down
23 changes: 10 additions & 13 deletions package.json
Expand Up @@ -11,23 +11,20 @@
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/core": "^7.9.0",
"@babel/eslint-plugin-development": "^1.0.1",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-dynamic-import": "^7.8.3",
"@babel/plugin-proposal-export-namespace-from": "^7.8.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-numeric-separator": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@babel/plugin-transform-flow-strip-types": "^7.8.3",
"@babel/plugin-transform-for-of": "^7.8.6",
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-flow": "^7.8.3",
"@babel/register": "^7.8.6",
"@babel/runtime": "^7.8.7",
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
"@babel/plugin-transform-flow-strip-types": "^7.9.0",
"@babel/plugin-transform-for-of": "^7.9.0",
"@babel/plugin-transform-modules-commonjs": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/preset-flow": "^7.9.0",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@rollup/plugin-json": "4.0.1",
"babel-eslint": "^11.0.0-beta.2",
"babel-jest": "^25.1.0",
Expand Down
22 changes: 12 additions & 10 deletions packages/babel-core/src/parser/util/missing-plugin-helper.js
Expand Up @@ -67,8 +67,8 @@ const pluginNameMap = {
url: "https://git.io/vb4yb",
},
transform: {
name: "@babel/plugin-transform-flow-strip-types",
url: "https://git.io/vb49g",
name: "@babel/preset-flow",
url: "https://git.io/JfeDn",
},
},
functionBind: {
Expand Down Expand Up @@ -103,8 +103,8 @@ const pluginNameMap = {
url: "https://git.io/vb4yA",
},
transform: {
name: "@babel/plugin-transform-react-jsx",
url: "https://git.io/vb4yd",
name: "@babel/preset-react",
url: "https://git.io/JfeDR",
},
},
logicalAssignment: {
Expand Down Expand Up @@ -159,8 +159,8 @@ const pluginNameMap = {
url: "https://git.io/vb4SC",
},
transform: {
name: "@babel/plugin-transform-typescript",
url: "https://git.io/vb4Sm",
name: "@babel/preset-typescript",
url: "https://git.io/JfeDz",
},
},

Expand Down Expand Up @@ -194,13 +194,15 @@ export default function generateMissingPluginMessage(
if (pluginInfo) {
const { syntax: syntaxPlugin, transform: transformPlugin } = pluginInfo;
if (syntaxPlugin) {
const syntaxPluginInfo = getNameURLCombination(syntaxPlugin);
if (transformPlugin) {
const transformPluginInfo = getNameURLCombination(transformPlugin);
helpMessage +=
`\n\nAdd ${transformPluginInfo} to the 'plugins' section of your Babel config ` +
`to enable transformation.`;
const sectionType = transformPlugin.name.startsWith("@babel/plugin")
? "plugins"
: "presets";
helpMessage += `\n\nAdd ${transformPluginInfo} to the '${sectionType}' section of your Babel config to enable transformation.
If you want to leave it as-is, add ${syntaxPluginInfo} to the 'plugins' section to enable parsing.`;
} else {
const syntaxPluginInfo = getNameURLCombination(syntaxPlugin);
helpMessage +=
`\n\nAdd ${syntaxPluginInfo} to the 'plugins' section of your Babel config ` +
`to enable parsing.`;
Expand Down
47 changes: 37 additions & 10 deletions packages/babel-helper-create-class-features-plugin/src/fields.js
Expand Up @@ -85,24 +85,49 @@ const privateNameVisitor = {
const { privateNamesMap } = this;
const body = path.get("body.body");

const visiblePrivateNames = new Map(privateNamesMap);
const redeclared = [];
for (const prop of body) {
if (!prop.isPrivate()) {
continue;
}
if (!privateNamesMap.has(prop.node.key.id.name)) continue;
if (!prop.isPrivate()) continue;
const { name } = prop.node.key.id;
visiblePrivateNames.delete(name);
redeclared.push(name);
}

// This class redeclares the private name.
// So, we can only evaluate the things in the outer scope.
path.traverse(privateNameInnerVisitor, this);
path.skip();
break;
// If the class doesn't redeclare any private fields, we can continue with
// our overall traversal.
if (!redeclared.length) {
return;
}

// This class redeclares some private field. We need to process the outer
// environment with access to all the outer privates, then we can process
// the inner environment with only the still-visible outer privates.
path.get("body").traverse(privateNameNestedVisitor, {
...this,
redeclared,
});
path.traverse(privateNameVisitor, {
...this,
privateNamesMap: visiblePrivateNames,
});

// We'll eventually hit this class node again with the overall Class
// Features visitor, which'll process the redeclared privates.
path.skipKey("body");
},
};

// Traverses the outer portion of a class, without touching the class's inner
// scope, for private names.
const privateNameInnerVisitor = traverse.visitors.merge([
const privateNameNestedVisitor = traverse.visitors.merge([
{
PrivateName(path) {
const { redeclared } = this;
const { name } = path.node.id;
if (redeclared.includes(name)) path.skip();
},
},
{
PrivateName: privateNameVisitor.PrivateName,
},
Expand Down Expand Up @@ -263,6 +288,8 @@ export function transformPrivateNamesUsage(
loose,
state,
) {
if (!privateNamesMap.size) return;

const body = path.get("body");

if (loose) {
Expand Down
26 changes: 22 additions & 4 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -1834,10 +1834,28 @@ export default class StatementParser extends ExpressionParser {
isExportDefaultSpecifier(): boolean {
if (this.match(tt.name)) {
return this.state.value !== "async" && this.state.value !== "let";
}
if (!this.match(tt._default)) {
const value = this.state.value;
if (value === "async" || value === "let") {
return false;
}
if (
(value === "type" || value === "interface") &&
!this.state.containsEsc
) {
const l = this.lookahead();
// If we see any variable name other than `from` after `type` keyword,
// we consider it as flow/typescript type exports
// note that this approach may fail on some pedantic cases
// export type from = number
if (
(l.type === tt.name && l.value !== "from") ||
l.type === tt.braceL
) {
this.expectOnePlugin(["flow", "typescript"]);
return false;
}
}
} else if (!this.match(tt._default)) {
return false;
}
Expand Down
@@ -0,0 +1 @@
export interface Foo {}
@@ -0,0 +1,7 @@
{
"sourceType": "module",
"plugins": [
"jsx"
],
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,2 @@
var Foo;
export type { Foo };
@@ -0,0 +1,7 @@
{
"sourceType": "module",
"plugins": [
"jsx"
],
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (2:7)"
}
@@ -0,0 +1 @@
export type Foo = number;
@@ -0,0 +1,7 @@
{
"sourceType": "module",
"plugins": [
"jsx"
],
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["jsx"]
}
@@ -0,0 +1 @@
export interface Foo {}
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,2 @@
var Foo;
export type { Foo };
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (2:7)"
}
@@ -0,0 +1 @@
export type Foo = number;
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'flow, typescript' (1:7)"
}
@@ -0,0 +1,3 @@
{
"sourceType": "module"
}
@@ -0,0 +1,19 @@
class Foo {
#foo = 1;

test() {
class Nested {
#foo = 2;

[this.#foo]() {
}
}

return new Nested();
}
}

const f = new Foo();
expect(() => {
f.test();
}).toThrow();

0 comments on commit f834534

Please sign in to comment.