Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid string concatenation breaks Lodash _.template method #413

Closed
filmic opened this issue Feb 9, 2017 · 3 comments · Fixed by #490
Closed

Invalid string concatenation breaks Lodash _.template method #413

filmic opened this issue Feb 9, 2017 · 3 comments · Fixed by #490
Milestone

Comments

@filmic
Copy link

filmic commented Feb 9, 2017

Minifing the Lodash library using Babili 0.0.11 breaks the _.template method.

The string concatenation in that method (https://github.com/lodash/lodash/blob/4.17.4/lodash.js#L14748) is minified to contain extraneous escape characters.

Input:

source = 'function(' + (variable || 'obj') + ') {\n' +
        (variable
          ? ''
          : 'obj || (obj = {});\n'
        ) +
        "var __t, __p = ''" +
        (isEscaping
           ? ', __e = _.escape'
           : ''
        ) +
        (isEvaluating
          ? ', __j = Array.prototype.join;\n' +
            "function print() { __p += __j.call(arguments, '') }\n"
          : ';\n'
        ) +
        source +
        'return __p\n}';

Output:
source='function('+(variable||'obj')+') {\n'+(variable?'':'obj || (obj = {});\n')+'var __t, __p = \'\''+(isEscaping?', __e = _.escape':'')+(isEvaluating?', __j = Array.prototype.join;\\nfunction print() { __p += __j.call(arguments, \\\'\\\') }\\n':';\n')+source+'return __p\n}';

Notice extra escape in \\n which results in \n in function body after Array.prototype.join:
... Array.prototype.join; \nfunction print() {...

That causes SyntaxError: Invalid or unexpected token when function is executed.

stropitek added a commit to NPellet/visualizer that referenced this issue Mar 30, 2017
This reverts commit 9577010.

We should wait for babel/minify#413 to be solved
@filmic
Copy link
Author

filmic commented Apr 3, 2017

Other escaping related issue: #440

@filmic
Copy link
Author

filmic commented Apr 3, 2017

@boopathi Any hint when this will be fixed?
It is a blocker for anyone using Lodash template method i.e. in Backbone project.

boopathi added a commit that referenced this issue Apr 3, 2017
+ Adds option isScriptContext to constant folding plugin
+ Fix #440, fix #413
+ Related #384, #382
@boopathi boopathi mentioned this issue Apr 3, 2017
boopathi added a commit that referenced this issue Apr 4, 2017
+ Adds option isScriptContext to constant folding plugin
+ Fix #440, fix #413
+ Related #384, #382
@vigneshshanmugam
Copy link
Member

@filmic Should be fixed once this PR #490 is merged

boopathi added a commit that referenced this issue Apr 6, 2017
* Make jsesc isScriptContext optional

+ Adds option isScriptContext to constant folding plugin
+ Fix #440, fix #413
+ Related #384, #382

* Remove jsesc
@boopathi boopathi added this to the 1.0 milestone Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants