google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 580 forks source link

continuation.js missing from dist/commonjs/runtime in Traceur 0.0.110 #2126

Open stuartZhang opened 8 years ago

stuartZhang commented 8 years ago

I upgrade the Google Traceur to the latest 0.0.110. However, the compilation-output ES5 JavaScript program can't work in the web browser.

1) The transpiling command for Traceur:

node_modules/.bin/traceur \ --script=www/js/widget-nest-thermostat.bbjs \ --out=www/js/widget-nest-thermostat.js \ --require=true \ --arrow-functions=true --block-binding=true --classes=true \ --computed-property-names=true --default-parameters=true \ --destructuring=true --for-of=true --generators=true --numeric-literals=true \ --property-methods=true --property-name-shorthand=true --rest-parameters=true \ --spread=true --symbols=true --template-literals=true --unicode-escape-sequences=true \ --unicode-expressions=true --proper-tail-calls=true --annotations=true \ --array-comprehension=true --async-functions=true --async-generators=true \ --exponentiation=true --export-from-extended=true --for-on=true \ --generator-comprehension=true --member-variables=true --spread-properties=true \ --types=true --experimental --source-maps=file

2) The traceur runtime has been introduced in the HTML page.

The file "traceur-runtime.js" is copied from the folder "node_modules/traceur/bin".

3) The Error is thrown from the web browser, when I visit the web page.

  **TypeError: Cannot read property 'default' of undefined**

By scanning the compilatio-output ES5 JS program, I discovered the error point is

var $__initTailRecursiveFunction = $traceurRuntime.getModule($traceurRuntime.normalizeModuleName("traceur/dist/commonjs/runtime/modules/initTailRecursiveFunction.js", "widget-nest-thermostat.bbjs")).default;

That's to say, $traceurRuntime.getModule($traceurRuntime.normalizeModuleName("traceur/dist/commonjs/runtime/modules/initTailRecursiveFunction.js", "widget-nest-thermostat.bbjs")) returns null.

Memo: in my project, ES6 JS file is suffixed with ".bbjs". After they are compiled, their corresponding ES5 file is ".js".

stuartZhang commented 8 years ago

It's worth saying that, as for the traceur@0.0.107, the compilation-output ES5 JavaScript program works in the web browser.

Is it a regression bug for the version 0.0.110?

johnjbarton commented 8 years ago

Please look in to your output for the $traceurRuntime.registerModule() with the name from your initTailRecursiveFunction.js. Also compare these with the the old and new versions of the compiler.

The compiler generates $traceurRuntime.registerModule() to store the modules and $traceurRuntime.getModule() to retrieve them. The register call must be missing or out of order.

Once you have a hint perhaps you can create a small test case. We did make some changes in the runtime.

stuartZhang commented 8 years ago

Given my investigation, the Traceur@0.0.110-compilation ES5 code is very different from Traceur@0.0.107.

The below JS statement is inexistent in the Traceur@0.0.107 compilation result. var $__continuation = $traceurRuntime.getModule($traceurRuntime.normalizeModuleName("traceur/dist/commonjs/runtime/modules/continuation.js", "widget-nest-thermostat.bbjs")).default;

On the contrary, in Traceur@0.0.110 compilation result, the above statement is in the 2nd line.

However, in the web browser, the above JS statement brings about a NullPointer error, because $traceurRuntime.getModule($traceurRuntime.normalizeModuleName("traceur/dist/commonjs/runtime/modules/continuation.js", "widget-nest-thermostat.bbjs")) return null.

The following picture shows the differences between Traceur@0.0.110 and Traceur@0.0.107 compilation results.

traceur_diff

johnjbarton commented 8 years ago

Looks like continuation.js did not make it into the commonjs runtime.

arv commented 8 years ago

I see dist/commonjs/runtime/modules/continuation.js in the npm release.

I suspect there is cyclic dependency with the require that causes this to be undefined. I'll try to create a minimal test case.

For now you can turn off import-runtime or turn off proper-tail-calls to get you unblocked.

richgilbank commented 8 years ago

Hey folks, thanks for the continued work on the project! 💃 Just wanted to leave a note here for anyone else currently experiencing issues with this - turning off properTailCalls didn't seem to do the trick for me, but turning off importRuntime did. ¯\(ツ)/¯ ref: https://github.com/richgilbank/Scratch-JS/commit/d0f2e7b51e6f207dc3940f756491500ae320f81a#diff-402dfb8c015ea27de73101a0b8d9fc32R17

stuartZhang commented 8 years ago

Cloud you please teach me what the feature "importRuntime" takes on during the transformation from ES 6 to ES 5?