Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
Fix transformation of <script> tags. Closes #84
Browse files Browse the repository at this point in the history
The problem was that the transformScriptTags attached to DOMContentLoaded took one argument (the event), which it was treating as a list of script tags to transform. This is obviously wrong. DOM-specific stuff like this needs more unit testing in babel-standalone.

Tested scriptTag-src.html and scriptTag-custom.html examples, both work as expected
  • Loading branch information
Daniel15 committed May 16, 2017
1 parent 7408d19 commit 225703f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-standalone",
"version": "6.24.1",
"version": "6.24.2",
"description": "Standalone build of Babel for use in non-Node.js environments. Similar to the (now deprecated) babel-browser",
"main": "babel.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const version = VERSION;
// 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', () => transformScriptTags(), false);
}

/**
Expand All @@ -274,4 +274,3 @@ export function transformScriptTags(scriptTags) {
export function disableScriptTags() {
window.removeEventListener('DOMContentLoaded', transformScriptTags);
}

7 changes: 2 additions & 5 deletions src/transformScriptTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,9 @@ function loadScripts(transformFn, scripts) {
* Run script tags with type="text/jsx".
* @param {Array} scriptTags specify script tags to run, run all in the <head> if not given
*/
export function runScripts(transformFn, scriptTags) {
let scripts
export function runScripts(transformFn, scripts) {
headEl = document.getElementsByTagName('head')[0];
if(scriptTags) {
scripts = scriptTags
} else {
if (!scripts) {
scripts = document.getElementsByTagName('script');
}

Expand Down

0 comments on commit 225703f

Please sign in to comment.