这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ aliases:
executors:
node-executor:
docker:
- image: circleci/node:latest
- image: cimg/node:current
working_directory: ~/babel
# e2e-vue-cli test requires chromium
node-browsers-executor:
docker:
- image: circleci/node:latest-browsers
- image: cimg/node:current-browsers
working_directory: ~/babel
# e2e-jest test requires python
node-python-executor:
docker:
- image: cimg/python:3.9-node
working_directory: ~/babel

jobs:
Expand Down Expand Up @@ -153,10 +158,14 @@ jobs:
- checkout
- attach_workspace:
at: /tmp/verdaccio-workspace
- run:
# vue-cli uses puppeteer, and it depends on the libXss.so.1 shared library
name: Install Headless Chrome dependencies
command: sudo apt-get install -yq libxss1
- run: ./scripts/integration-tests/e2e-vue-cli.sh

e2e-jest:
executor: node-executor
executor: node-python-executor
steps:
- checkout
- attach_workspace:
Expand Down
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/Bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assignees: ''
**Current behavior**
<!-- A clear and concise description of the behavior. -->

- [REPL](babeljs.io/repl), [Codesandbox](https://codesandbox.io/s/babel-repl-custom-plugin-7s08o?file=/src/index.js), or GitHub Repo helps!
- [REPL](https://babel.dev/repl), [Codesandbox](https://codesandbox.io/s/babel-repl-custom-plugin-7s08o?file=/src/index.js), or GitHub Repo may increase triaging priority!

**Input Code**

Expand All @@ -45,11 +45,11 @@ var your => (code) => here;
```

```
- Babel version(s): [e.g. v6.0.0, v7.0.0-beta.34]
- Node/npm version: [e.g. Node 8/npm 5]
- OS: [e.g. OSX 10.13.4, Windows 10]
- Babel version(s): [e.g. v7.12.0]
- Node/npm version: [e.g. Node 12/npm 7]
- OS: [e.g. macOS 10.15.4, Windows 10]
- Monorepo: [e.g. yes/no/Lerna]
- How you are using Babel: [e.g. `cli`, `register`, `loader`]
- How you are using Babel: [e.g. `webpack`, `rollup`, `parcel`, `babel-register`]

**Possible Solution**
<!--- If you have suggestions on a fix for the bug -->
Expand Down
6 changes: 3 additions & 3 deletions .yarn/plugins/@yarnpkg/plugin-babel-release-tool.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-2.3.1.cjs

This file was deleted.

55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Use Yarn 2
# This path should always match the one in .yarnrc.yml
yarn-path ".yarn/releases/yarn-2.3.1.cjs"
yarn-path ".yarn/releases/yarn-2.4.0.cjs"
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ releaseTool:
unsafeHttpWhitelist:
- localhost

yarnPath: .yarn/releases/yarn-2.3.1.cjs
yarnPath: .yarn/releases/yarn-2.4.0.cjs
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ clean: test-clean

clean-tsconfig:
rm -f tsconfig.json
rm -f packages/*/tsconfig.{tsbuildinfo,json}
rm -f codemods/*/tsconfig.{tsbuildinfo,json}
rm -f eslint/*/tsconfig.{tsbuildinfo,json}
git clean packages/*/tsconfig.json -xfq
git clean codemods/*/tsconfig.json -xfq
git clean eslint/*/tsconfig.json -xfq
rm -f */*/tsconfig.tsbuildinfo

test-clean:
$(foreach source, $(SOURCES), \
Expand Down Expand Up @@ -238,9 +239,9 @@ publish:

check-yarn-bug-1882:
ifneq ("$(shell grep 3155328e5 .yarn/releases/yarn-*.cjs -c)", "0")
echo "Your version of yarn is affected by https://github.com/yarnpkg/berry/issues/1882"
echo "Please run `sed -i -e "s/3155328e5/4567890e5/g" .yarn/releases/yarn-*.cjs`"
exit 1
@echo "Your version of yarn is affected by https://github.com/yarnpkg/berry/issues/1882"
@echo "Please run \`sed -i -e "s/3155328e5/4567890e5/g" .yarn/releases/yarn-*.cjs\`"
@exit 1
endif

publish-ci: prepublish
Expand All @@ -259,6 +260,7 @@ ifneq ("$(I_AM_USING_VERDACCIO)", "I_AM_SURE")
echo "You probably don't know what you are doing"
exit 1
endif
$(MAKE) check-yarn-bug-1882
$(YARN) release-tool version $(VERSION) --all --yes --tag-version-prefix="version-e2e-test-"
$(MAKE) prepublish-build
YARN_NPM_PUBLISH_REGISTRY=http://localhost:4873 $(YARN) release-tool publish --yes --tag-version-prefix="version-e2e-test-"
Expand Down
135 changes: 98 additions & 37 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (api) {
let convertESM = true;
let ignoreLib = true;
let includeRegeneratorRuntime = false;
let polyfillRequireResolve = false;
let needsPolyfillsForOldNode = false;

let transformRuntimeOptions;

Expand Down Expand Up @@ -54,15 +54,15 @@ module.exports = function (api) {
"packages/babel-compat-data"
);
if (env === "rollup") envOpts.targets = { node: nodeVersion };
polyfillRequireResolve = true;
needsPolyfillsForOldNode = true;
break;
case "test-legacy": // In test-legacy environment, we build babel on latest node but test on minimum supported legacy versions
case "production":
// Config during builds before publish.
envOpts.targets = {
node: nodeVersion,
};
polyfillRequireResolve = true;
needsPolyfillsForOldNode = true;
break;
case "development":
envOpts.debug = true;
Expand All @@ -79,7 +79,7 @@ module.exports = function (api) {

if (process.env.STRIP_BABEL_8_FLAG && bool(process.env.BABEL_8_BREAKING)) {
// Never apply polyfills when compiling for Babel 8
polyfillRequireResolve = false;
needsPolyfillsForOldNode = false;
}

if (includeRegeneratorRuntime) {
Expand Down Expand Up @@ -129,7 +129,7 @@ module.exports = function (api) {
pluginToggleBabel8Breaking,
{ breaking: bool(process.env.BABEL_8_BREAKING) },
],
polyfillRequireResolve && pluginPolyfillRequireResolve,
needsPolyfillsForOldNode && pluginPolyfillsOldNode,
].filter(Boolean),
overrides: [
{
Expand Down Expand Up @@ -177,44 +177,105 @@ module.exports = function (api) {

// env vars from the cli are always strings, so !!ENV_VAR returns true for "false"
function bool(value) {
return value && value === "false" && value === "0";
return value && value !== "false" && value !== "0";
}

// TODO(Babel 8) This polyfill is only needed for Node.js 6 and 8
function pluginPolyfillRequireResolve({ template, types: t }) {
// TODO(Babel 8) This polyfills are only needed for Node.js 6 and 8
/** @param {import("@babel/core")} api */
function pluginPolyfillsOldNode({ template, types: t }) {
const polyfills = [
{
name: "require.resolve",
necessary({ node, parent }) {
return (
t.isCallExpression(parent, { callee: node }) &&
parent.arguments.length > 1
);
},
supported({ parent: { arguments: args } }) {
return (
t.isObjectExpression(args[1]) &&
args[1].properties.length === 1 &&
t.isIdentifier(args[1].properties[0].key, { name: "paths" }) &&
t.isArrayExpression(args[1].properties[0].value) &&
args[1].properties[0].value.elements.length === 1
);
},
// require.resolve's paths option has been introduced in Node.js 8.9
// https://nodejs.org/api/modules.html#modules_require_resolve_request_options
replacement: template({ syntacticPlaceholders: true })`
parseFloat(process.versions.node) >= 8.9
? require.resolve
: (/* request */ r, { paths: [/* base */ b] }, M = require("module")) => {
let /* filename */ f = M._findPath(r, M._nodeModulePaths(b).concat(b));
if (f) return f;
f = new Error(\`Cannot resolve module '\${r}'\`);
f.code = "MODULE_NOT_FOUND";
throw f;
}
`,
},
{
// NOTE: This polyfills depends on the "make-dir" library. Any package
// using fs.mkdirSync must have "make-dir" as a dependency.
name: "fs.mkdirSync",
necessary({ node, parent }) {
return (
t.isCallExpression(parent, { callee: node }) &&
parent.arguments.length > 1
);
},
supported({ parent: { arguments: args } }) {
return (
t.isObjectExpression(args[1]) &&
args[1].properties.length === 1 &&
t.isIdentifier(args[1].properties[0].key, { name: "recursive" }) &&
t.isBooleanLiteral(args[1].properties[0].value, { value: true })
);
},
// fs.mkdirSync's recursive option has been introduced in Node.js 10.12
// https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_options
replacement: template`
parseFloat(process.versions.node) >= 10.12
? fs.mkdirSync
: require("make-dir").sync
`,
},
{
// NOTE: This polyfills depends on the "node-environment-flags"
// library. Any package using process.allowedNodeEnvironmentFlags
// must have "node-environment-flags" as a dependency.
name: "process.allowedNodeEnvironmentFlags",
necessary({ parent, node }) {
// To avoid infinite replacement loops
return !t.isLogicalExpression(parent, { operator: "||", left: node });
},
supported: () => true,
// process.allowedNodeEnvironmentFlags has been introduced in Node.js 10.10
// https://nodejs.org/api/process.html#process_process_allowednodeenvironmentflags
replacement: template`
process.allowedNodeEnvironmentFlags || require("node-environment-flags")
`,
},
];

return {
visitor: {
MemberExpression(path) {
if (!path.matchesPattern("require.resolve")) return;
if (!t.isCallExpression(path.parent, { callee: path.node })) return;

const args = path.parent.arguments;
if (args.length < 2) return;
if (
!t.isObjectExpression(args[1]) ||
args[1].properties.length !== 1 ||
!t.isIdentifier(args[1].properties[0].key, { name: "paths" }) ||
!t.isArrayExpression(args[1].properties[0].value) ||
args[1].properties[0].value.elements.length !== 1
) {
throw path.parentPath.buildCodeFrameError(
"This 'require.resolve' usage is not supported by the inline polyfill."
);
}
for (const polyfill of polyfills) {
if (!path.matchesPattern(polyfill.name)) continue;

if (!polyfill.necessary(path)) return;
if (!polyfill.supported(path)) {
throw path.buildCodeFrameError(
`This '${polyfill.name}' usage is not supported by the inline polyfill.`
);
}

// require.resolve's paths option has been introduced in Node.js 8.9
// https://nodejs.org/api/modules.html#modules_require_resolve_request_options
path.replaceWith(template.ast`
parseFloat(process.versions.node) >= 8.9
? require.resolve
: (/* request */ r, { paths: [/* base */ b] }, M = require("module")) => {
let /* filename */ f = M._findPath(r, M._nodeModulePaths(b).concat(b));
if (f) return f;
f = new Error(\`Cannot resolve module '\${r}'\`);
f.code = "MODULE_NOT_FOUND";
throw f;
}
`);
path.replaceWith(polyfill.replacement());

break;
}
},
},
};
Expand Down
5 changes: 2 additions & 3 deletions packages/babel-cli/src/babel/dir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow

import debounce from "lodash/debounce";
import { sync as makeDirSync } from "make-dir";
import slash from "slash";
import path from "path";
import fs from "fs";
Expand All @@ -17,7 +16,7 @@ const FILE_TYPE = Object.freeze({
});

function outputFileSync(filePath: string, data: string | Buffer): void {
makeDirSync(path.dirname(filePath));
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, data);
}

Expand Down Expand Up @@ -163,7 +162,7 @@ export default async function ({
util.deleteDir(cliOptions.outDir);
}

makeDirSync(cliOptions.outDir);
fs.mkdirSync(cliOptions.outDir, { recursive: true });

startTime = process.hrtime();

Expand Down
3 changes: 1 addition & 2 deletions packages/babel-cli/src/babel/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import convertSourceMap from "convert-source-map";
import sourceMap from "source-map";
import slash from "slash";
import { sync as makeDirSync } from "make-dir";
import path from "path";
import fs from "fs";

Expand Down Expand Up @@ -89,7 +88,7 @@ export default async function ({
const result = buildResult(fileResults);

if (cliOptions.outFile) {
makeDirSync(path.dirname(cliOptions.outFile));
fs.mkdirSync(path.dirname(cliOptions.outFile), { recursive: true });

// we've requested for a sourcemap to be written to disk
if (babelOptions.sourceMaps && babelOptions.sourceMaps !== "inline") {
Expand Down
15 changes: 15 additions & 0 deletions packages/babel-generator/src/generators/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,18 @@ export function V8IntrinsicIdentifier(node: Object) {
this.token("%");
this.word(node.name);
}

export function ModuleExpression(node: Object) {
this.word("module");
this.space();
this.token("{");
if (node.body.length === 0) {
this.token("}");
} else {
this.newline();
this.printSequence(node.body, node, {
indent: true,
});
this.rightBrace();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const m = module { export const foo = "foo" };
module {
foo;
bar;
};
foo(module {});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["jsModuleBlocks"],
"sourceType": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const m = module {
export const foo = "foo";
};
module {
foo;
bar;
};
foo(module {});
Loading