Fix moduleAttributesVersion errors with stage-0 preset in babel standalone (#11631)
* Fix moduleAttributesVersion errors with stage-0 preset in babel standalone * Add regression test for stage-0 not erroring on missing moduleattributes version * Remove moduleAttributesVersion from preset config
This commit is contained in:
parent
ddfdf00167
commit
8e41f26e12
@ -3,11 +3,11 @@ import { declare } from "@babel/helper-plugin-utils";
|
|||||||
export default declare((api, { version }) => {
|
export default declare((api, { version }) => {
|
||||||
api.assertVersion(7);
|
api.assertVersion(7);
|
||||||
|
|
||||||
if (typeof version !== "string" || version !== "apr-2020") {
|
if (typeof version !== "string" || version !== "may-2020") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"The 'moduleAttributes' plugin requires a 'version' option," +
|
"The 'moduleAttributes' plugin requires a 'version' option," +
|
||||||
" representing the last proposal update. Currently, the" +
|
" representing the last proposal update. Currently, the" +
|
||||||
" only supported value is 'apr-2020'.",
|
" only supported value is 'may-2020'.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,48 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>babel-standalone example</title>
|
<title>babel-standalone example</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
Input:
|
Input:
|
||||||
<textarea id="input" style="width: 100%" rows="10">
|
<textarea id="input" style="width: 100%" rows="10">
|
||||||
const getMessage = () => 'Hello World';
|
const getMessage = () => 'Hello World';
|
||||||
const someDiv = <div>{getMessage()}</div>;
|
const someDiv = <div>{getMessage()}</div>;
|
||||||
</textarea>
|
</textarea
|
||||||
|
>
|
||||||
|
|
||||||
Transformed code using Babel <strong id="version"></strong>:
|
Transformed code using Babel <strong id="version"></strong>:
|
||||||
<pre id="output">Loading...</pre>
|
<pre id="output">Loading...</pre>
|
||||||
|
|
||||||
<script src="../babel.js"></script>
|
<script src="../babel.js"></script>
|
||||||
<script>
|
<script>
|
||||||
console.log('Babel =', Babel);
|
console.log("Babel =", Babel);
|
||||||
document.getElementById('version').innerHTML = Babel.version;
|
document.getElementById("version").innerHTML = Babel.version;
|
||||||
var inputEl = document.getElementById('input');
|
var inputEl = document.getElementById("input");
|
||||||
var outputEl = document.getElementById('output');
|
var outputEl = document.getElementById("output");
|
||||||
|
|
||||||
function transform() {
|
function transform() {
|
||||||
try {
|
try {
|
||||||
outputEl.innerHTML = Babel.transform(inputEl.value, {
|
outputEl.innerHTML = Babel.transform(inputEl.value, {
|
||||||
presets: ['es2015', 'react', 'stage-0']
|
presets: [
|
||||||
|
"es2015",
|
||||||
|
"react",
|
||||||
|
[
|
||||||
|
"stage-0",
|
||||||
|
{
|
||||||
|
decoratorsBeforeExport: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
}).code;
|
}).code;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
outputEl.innerHTML = 'ERROR: ' + ex.message;
|
outputEl.innerHTML = "ERROR: " + ex.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inputEl.addEventListener('keyup', transform, false);
|
inputEl.addEventListener("keyup", transform, false);
|
||||||
transform();
|
transform();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -9,6 +9,7 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
decoratorsLegacy = false,
|
decoratorsLegacy = false,
|
||||||
decoratorsBeforeExport,
|
decoratorsBeforeExport,
|
||||||
pipelineProposal = "minimal",
|
pipelineProposal = "minimal",
|
||||||
|
moduleAttributesVersion = "may-2020",
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -21,6 +22,7 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
decoratorsLegacy,
|
decoratorsLegacy,
|
||||||
decoratorsBeforeExport,
|
decoratorsBeforeExport,
|
||||||
pipelineProposal,
|
pipelineProposal,
|
||||||
|
moduleAttributesVersion,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@ -203,6 +203,13 @@
|
|||||||
Babel.transform("/a*/u", { presets: ["es2015"] }),
|
Babel.transform("/a*/u", { presets: ["es2015"] }),
|
||||||
).not.toThrow();
|
).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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user