inline option throwing error #1282

Closed
juancabrera opened this Issue Aug 20, 2014 · 14 comments

Comments

Projects
None yet
3 participants
@juancabrera

Every time I try to transpile a JS file it breaks when it's has the "inline" option, AMD and CJS options are working fine.

This is the error I got.

events.js:72
        throw er; // Unhandled 'error' event
              ^
TypeError: Cannot call method 'replace' of undefined
    at InlineModuleTransformer.getTempVarNameForModuleName (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:13434:33)
    at InlineModuleTransformer.wrapModule (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:17912:25)
    at InlineModuleTransformer.transformModule (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:13452:25)
    at Module.transform (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:6122:26)
    at InlineModuleTransformer.transformAny (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:11621:27)
    at FromOptionsTransformer.append (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:22181:55)
    at eval (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:21125:16)
    at Array.every (native)
    at FromOptionsTransformer.transform (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:21124:30)
    at Compiler.treeToTree (eval at <anonymous> (/Users/cabrera/htdocs/gulp-core-slim-sass-es6/node_modules/gulp-traceur/node_modules/traceur/src/node/traceur.js:24:17), <anonymous>:22437:41)

@juancabrera juancabrera changed the title from inline option not working to inline option throwing error Aug 20, 2014

@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

Please post a specific example the the version you are using, eg ./traceur -v

Contributor

johnjbarton commented Aug 20, 2014

Please post a specific example the the version you are using, eg ./traceur -v

@juancabrera

This comment has been minimized.

Show comment
Hide comment
@juancabrera

juancabrera Aug 20, 2014

@johnjbarton

"traceur": "0.0.58" (from my package.json)

Actual testing code:

// half.js
export function Half(n) {
  this.halfNumber = n / 2;
};
// main.js
import {Half} from 'half';
var number = new Half(10);

Weird thing is that if I run traceur on the command line it works fine:

traceur --out main-out.js --modules=inline main.js; cat main-out.js

I start debugging and it breaks on traceur.compile (it just breaks when it has the inline option):

traceur.compile(file.contents.toString(), {modules:"inline"}); 

@johnjbarton

"traceur": "0.0.58" (from my package.json)

Actual testing code:

// half.js
export function Half(n) {
  this.halfNumber = n / 2;
};
// main.js
import {Half} from 'half';
var number = new Half(10);

Weird thing is that if I run traceur on the command line it works fine:

traceur --out main-out.js --modules=inline main.js; cat main-out.js

I start debugging and it breaks on traceur.compile (it just breaks when it has the inline option):

traceur.compile(file.contents.toString(), {modules:"inline"}); 
@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

Looks like the modulesName is not being set.

Contributor

johnjbarton commented Aug 20, 2014

Looks like the modulesName is not being set.

@juancabrera

This comment has been minimized.

Show comment
Hide comment
@juancabrera

juancabrera Aug 20, 2014

@johnjbarton not sure what you mean..

@johnjbarton not sure what you mean..

@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

I mean: It looks like we have a bug in options processing where we forget that inline modules need moduleName to be defined.

Contributor

johnjbarton commented Aug 20, 2014

I mean: It looks like we have a bug in options processing where we forget that inline modules need moduleName to be defined.

@juancabrera juancabrera referenced this issue in sindresorhus/gulp-traceur Aug 20, 2014

Closed

inline option not working #30

@juancabrera

This comment has been minimized.

Show comment
Hide comment
@juancabrera

juancabrera Aug 20, 2014

Looking into it now, added a random name to this.moduleName in InlineModuleTransformer and it didn't throw any error, but is not "concatenating" the modules in one file (in this case is not adding half.js):

This is the output:

var $__inlinetest0_46_6322336730081588__ = (function() {
  "use strict";
  var Half = ($__half__).Half;
  var number = new Half(10);
  return {};
})();

Not sure if it's related because I didn't add the name properly to it, or if something else is not working. Any hint/thoughts ?

Looking into it now, added a random name to this.moduleName in InlineModuleTransformer and it didn't throw any error, but is not "concatenating" the modules in one file (in this case is not adding half.js):

This is the output:

var $__inlinetest0_46_6322336730081588__ = (function() {
  "use strict";
  var Half = ($__half__).Half;
  var number = new Half(10);
  return {};
})();

Not sure if it's related because I didn't add the name properly to it, or if something else is not working. Any hint/thoughts ?

@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

The compile() function just compiles. You have to concatenate if that is what you want.

Contributor

johnjbarton commented Aug 20, 2014

The compile() function just compiles. You have to concatenate if that is what you want.

@juancabrera

This comment has been minimized.

Show comment
Hide comment
@juancabrera

juancabrera Aug 20, 2014

I see, I thought it was suppose to work the same way the command line is working the "inline" modules.

@rolftimmermans I saw you built this part and just wanted to see if you have any thoughts/ideas ?

I see, I thought it was suppose to work the same way the command line is working the "inline" modules.

@rolftimmermans I saw you built this part and just wanted to see if you have any thoughts/ideas ?

juancabrera referenced this issue Aug 20, 2014

New module compilation option: inline
This PR adds a new module transformer `inline` that produces very trivial module output when compiled as a single file. A module will be compiled to something like this:

```
var $__module__static_47_scripts_47_modules_47_TargetView_46_js__ = (function() {
  "use strict";
  var __moduleName = "static/scripts/modules/TargetView.js";
  // ...
}).call(this);
```

References to the module simply become: `__module__static_47_scripts_47_modules_47_TargetView_46_js__`

As I see it is has the following advantages when compiled in single-file mode:
- friendlier for compression tools like UglifyJS and Google Closure compiler, which can rename the lengthy module names to single variable names
- does not leak information about file structure when minified (`__moduleName` is often unused and is also stripped)
- no need for a module store in the runtime (although obviously this patch does not change the fact that it's there and compressors are not smart enough to remove it when minifying)

I'd love to see the single-file output of Traceur be a little more friendlier for web-use and JS minification tools. I hope this is one step in that direction.

The default in single-file compilation mode was not changed although I'd imagine that might be much more helpful for users unaware of this configuration option.

When I apply this change and remove the module store and url module from the runtime I can get a small sample project down from ~21KB uncompressed to ~16KB uncompressed.

Please consider this PR and let me know if there's anything I can do to improve the implementation or the test coverage.

Review URL: https://api.github.com/repos/google/traceur-compiler/issues/702

Closes #702.
@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

What makes you think the compile() command should work like the command
line? Its just a source to source transcoding step. It does not load any
other source.

If you want to load all of the modules recursively you can try
System.import('./main').then(function(main) {...}); I guess you have to
set the options globally. (I'm unclear since I been working on a different
branch lately.)

There are also functions in api.js that you can use for node-only work.

On Wed, Aug 20, 2014 at 1:56 PM, Juan Cabrera notifications@github.com
wrote:

I see, I thought it was suppose to work the same way the command line is
working the "inline" modules.

@rolftimmermans https://github.com/rolftimmermans I saw you built this
part and just wanted to see if you have any thoughts/ideas ?


Reply to this email directly or view it on GitHub
#1282 (comment)
.

Contributor

johnjbarton commented Aug 20, 2014

What makes you think the compile() command should work like the command
line? Its just a source to source transcoding step. It does not load any
other source.

If you want to load all of the modules recursively you can try
System.import('./main').then(function(main) {...}); I guess you have to
set the options globally. (I'm unclear since I been working on a different
branch lately.)

There are also functions in api.js that you can use for node-only work.

On Wed, Aug 20, 2014 at 1:56 PM, Juan Cabrera notifications@github.com
wrote:

I see, I thought it was suppose to work the same way the command line is
working the "inline" modules.

@rolftimmermans https://github.com/rolftimmermans I saw you built this
part and just wanted to see if you have any thoughts/ideas ?


Reply to this email directly or view it on GitHub
#1282 (comment)
.

@juancabrera

This comment has been minimized.

Show comment
Hide comment
@juancabrera

juancabrera Aug 20, 2014

I guess is the context of the project I'm working (gulp project for browser), so I was using gulp-traceur, what it basically does is call to traceur.compile passing the options, one of those options is the output for modules. So, as the project is for browser (and I don't want to use AMD) I kinda need the inline modules behave in the same way than the command line.

I guess is the context of the project I'm working (gulp project for browser), so I was using gulp-traceur, what it basically does is call to traceur.compile passing the options, one of those options is the output for modules. So, as the project is for browser (and I don't want to use AMD) I kinda need the inline modules behave in the same way than the command line.

@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Aug 20, 2014

Contributor

To use inline in the browser, compile in the server and include the result
in the web page.

On Wed, Aug 20, 2014 at 2:30 PM, Juan Cabrera notifications@github.com
wrote:

I guess is the context of the project I'm working (gulp project for
browser), so I was using gulp-traceur
https://github.com/sindresorhus/gulp-traceur, what it basically does is
call to traceur.compile passing the options, one of those options is the
output for modules. So, as the project is for browser (and I don't want to
use AMD) I kinda need the inline modules behave in the same way than the
command line.


Reply to this email directly or view it on GitHub
#1282 (comment)
.

Contributor

johnjbarton commented Aug 20, 2014

To use inline in the browser, compile in the server and include the result
in the web page.

On Wed, Aug 20, 2014 at 2:30 PM, Juan Cabrera notifications@github.com
wrote:

I guess is the context of the project I'm working (gulp project for
browser), so I was using gulp-traceur
https://github.com/sindresorhus/gulp-traceur, what it basically does is
call to traceur.compile passing the options, one of those options is the
output for modules. So, as the project is for browser (and I don't want to
use AMD) I kinda need the inline modules behave in the same way than the
command line.


Reply to this email directly or view it on GitHub
#1282 (comment)
.

johnjbarton added a commit to johnjbarton/traceur-compiler that referenced this issue Aug 22, 2014

@BernhardPosselt

This comment has been minimized.

Show comment
Hide comment
@BernhardPosselt

BernhardPosselt Sep 2, 2014

Can we have a release soon :)?

This is completely breaking my build

Can we have a release soon :)?

This is completely breaking my build

@johnjbarton

This comment has been minimized.

Show comment
Hide comment
@johnjbarton

johnjbarton Sep 2, 2014

Contributor

done

On Tue, Sep 2, 2014 at 9:21 AM, Bernhard Posselt notifications@github.com
wrote:

Can we have a release soon :)?

This is completely breaking my build


Reply to this email directly or view it on GitHub
#1282 (comment)
.

Contributor

johnjbarton commented Sep 2, 2014

done

On Tue, Sep 2, 2014 at 9:21 AM, Bernhard Posselt notifications@github.com
wrote:

Can we have a release soon :)?

This is completely breaking my build


Reply to this email directly or view it on GitHub
#1282 (comment)
.

@BernhardPosselt

This comment has been minimized.

Show comment
Hide comment
@BernhardPosselt

BernhardPosselt Sep 2, 2014

Thanks a lot :)

Thanks a lot :)

@juancabrera juancabrera referenced this issue in sindresorhus/gulp-traceur Dec 9, 2014

Closed

Manually compiling with traceur produces different output #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment