Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moduleAttributesVersion errors with stage-0 preset in babel standalone #11631

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/babel-plugin-syntax-module-attributes/src/index.js
Expand Up @@ -3,11 +3,11 @@ import { declare } from "@babel/helper-plugin-utils";
export default declare((api, { version }) => {
api.assertVersion(7);

if (typeof version !== "string" || version !== "apr-2020") {
if (typeof version !== "string" || version !== "may-2020") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

throw new Error(
"The 'moduleAttributes' plugin requires a 'version' option," +
" representing the last proposal update. Currently, the" +
" only supported value is 'apr-2020'.",
" only supported value is 'may-2020'.",
);
}

Expand Down
66 changes: 38 additions & 28 deletions packages/babel-standalone/examples/example.htm
@@ -1,38 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>babel-standalone example</title>
</head>
<body>
Input:
<textarea id="input" style="width: 100%" rows="10">
<head>
<meta charset="utf-8" />
<title>babel-standalone example</title>
</head>
<body>
Input:
<textarea id="input" style="width: 100%" rows="10">
const getMessage = () => 'Hello World';
const someDiv = <div>{getMessage()}</div>;
</textarea>
</textarea
>

Transformed code using Babel <strong id="version"></strong>:
<pre id="output">Loading...</pre>
Transformed code using Babel <strong id="version"></strong>:
<pre id="output">Loading...</pre>

<script src="../babel.js"></script>
<script>
console.log('Babel =', Babel);
document.getElementById('version').innerHTML = Babel.version;
var inputEl = document.getElementById('input');
var outputEl = document.getElementById('output');
<script src="../babel.js"></script>
<script>
console.log("Babel =", Babel);
document.getElementById("version").innerHTML = Babel.version;
var inputEl = document.getElementById("input");
var outputEl = document.getElementById("output");

function transform() {
try {
outputEl.innerHTML = Babel.transform(inputEl.value, {
presets: ['es2015', 'react', 'stage-0']
}).code;
} catch (ex) {
outputEl.innerHTML = 'ERROR: ' + ex.message;
function transform() {
try {
outputEl.innerHTML = Babel.transform(inputEl.value, {
presets: [
"es2015",
"react",
[
"stage-0",
{
decoratorsBeforeExport: false,
hamlim marked this conversation as resolved.
Show resolved Hide resolved
},
],
],
}).code;
} catch (ex) {
outputEl.innerHTML = "ERROR: " + ex.message;
}
}
}

inputEl.addEventListener('keyup', transform, false);
transform();
</script>
</body>
inputEl.addEventListener("keyup", transform, false);
transform();
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions packages/babel-standalone/src/preset-stage-0.js
Expand Up @@ -9,6 +9,7 @@ export default (_: any, opts: Object = {}) => {
decoratorsLegacy = false,
decoratorsBeforeExport,
pipelineProposal = "minimal",
moduleAttributesVersion = "may-2020",
} = opts;

return {
Expand All @@ -21,6 +22,7 @@ export default (_: any, opts: Object = {}) => {
decoratorsLegacy,
decoratorsBeforeExport,
pipelineProposal,
moduleAttributesVersion,
},
],
],
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-standalone/test/babel.js
Expand Up @@ -203,6 +203,13 @@
Babel.transform("/a*/u", { presets: ["es2015"] }),
).not.toThrow();
});
it("#11628 - supports stage-0 passing moduleAttributesVersion to stage-1", () => {
expect(() =>
Babel.transform("const getMessage = () => 'Hello World'", {
presets: [["stage-0", { decoratorsBeforeExport: false }]],
}),
).not.toThrow();
});
});
},
);