[@babel/standalone] Remove additional function context (#7094)

This commit is contained in:
Steve Fan 2018-01-05 11:15:51 +08:00 committed by Brian Ng
parent aec6e5c370
commit 1ded1d7ff6
2 changed files with 25 additions and 6 deletions

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>babel-standalone example - Script tag</title>
</head>
<body>
<pre id="output">This line should not be overwritten!</pre>
<script src="../babel.js"></script>
<script>Babel.disableScriptTags()</script>
<script type="text/babel">
const doStuff = () => {
document.getElementById('output').innerHTML = `I did an evil operation!`;
};
doStuff();
</script>
</body>
</html>

View File

@ -244,14 +244,14 @@ registerPresets({
export const version = VERSION;
function onDOMContentLoaded() {
transformScriptTags();
}
// Listen for load event if we're in a browser and then kick off finding and
// running of scripts with "text/babel" type.
if (typeof window !== "undefined" && window && window.addEventListener) {
window.addEventListener(
"DOMContentLoaded",
() => transformScriptTags(),
false,
);
window.addEventListener("DOMContentLoaded", onDOMContentLoaded, false);
}
/**
@ -266,5 +266,5 @@ export function transformScriptTags(scriptTags) {
* Disables automatic transformation of <script> tags with "text/babel" type.
*/
export function disableScriptTags() {
window.removeEventListener("DOMContentLoaded", transformScriptTags);
window.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
}