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

Broken unicode symbol after minification #6521

Closed
tandu opened this issue Jan 17, 2016 · 22 comments
Closed

Broken unicode symbol after minification #6521

tandu opened this issue Jan 17, 2016 · 22 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tandu
Copy link

tandu commented Jan 17, 2016

smile:before {
  content: "\200B";
}

Is compressed to

smile:before {
  content: "200B";
}

mgechev/angular-seed#390

@shmuelie
Copy link

Using what minifier?

@tandu
Copy link
Author

tandu commented Jan 17, 2016

As @mgechev says "The combination of ng2-inline-templates & typescript breaks the CSS.".

@tandu
Copy link
Author

tandu commented Jan 17, 2016

Check our discussion here mgechev/angular-seed#390

@blakeembrey
Copy link
Contributor

@tandu Have you tried using two backslashes? It's in a string, so you need to escape the backslash to use it.

Edit: To be clear, I don't know Angular. Just going off the inline template comment (mgechev/angular-seed#390 (comment)) which is using a string, hence the backslash needs to be escaped.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

In that case css for angular2-seed in dev mode works incorrectly. I.e. dev and prod modes handle this css rule differently.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

Here is zipped application that introduces the issue https://github.com/mgechev/angular2-seed/files/92926/angular2-seed.zip

@blakeembrey
Copy link
Contributor

@tandu I can't comment on Angular-specifics, but if this is inside a JavaScript string, it needs two backslashes to be in the output. The fact that it sounds like it works in dev is the bug to me.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

In dev css is not minified I think this is the difference. In css unicode symbol should be defined using one slash, check here, for example: http://stackoverflow.com/questions/10393462/placing-unicode-character-in-css-content-value so it looks like a bug that minifier requires 2 backslashes.

@blakeembrey
Copy link
Contributor

if this is inside a JavaScript string, it needs two backslashes to be in the output

@tandu No, it's not. You're writing JavaScript, not CSS (well, it's CSS inside of a JavaScript string) - so you need to escape the backslash in a JavaScript string, it's just how JavaScript works. I don't know how it's even working in dev, since it shouldn't.

You might want to read up on strings in JavaScript, if you're interested. But a backslash is an escape character. To have a backslash in the output, you need a backslash to escape another backslash - two backslashes.

@blakeembrey
Copy link
Contributor

@tandu I just downloaded your zip - is it in the CSS file? TypeScript isn't the right place for the issue on CSS. As for the comment by @mgechev, I believe his example was wrong because it would need two backslashes.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

I understand how escaping in strings is working. But if you are provided a real css to be minified either minifier should respect its single backslashes or css string should be parsed by regexp to replace single backslashes to double once.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

In example cd to dist/prod and run test server from here: python -m SimpleHTTPServer then open it at localhost:8000 in browser.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

To run it in dev you need to do some steps:

npm install tsd -g
npm install
npm start

@blakeembrey
Copy link
Contributor

@tandu It's not a TypeScript bug if it's in CSS. You should log the issue in the minifier repo you've mentioned.

@tandu
Copy link
Author

tandu commented Jan 17, 2016

Yes, I think you are right, I will talk with them.

@blakeembrey
Copy link
Contributor

@tandu Looks like it's caused in https://github.com/ludohenin/gulp-inline-ng2-template/blob/master/parser.js#L164-L167, they are just printing the backslashes back into JS without any additional escaping. They need to replace every backslash with two backslashes.

@vladima
Copy link
Contributor

vladima commented Jan 17, 2016

as I understand originally it appear when \200B had appeared in string template?

@Component({
  template: '',
  styles: [`
    smile:before {
      content: "\200B";
    }
  `]
})
class SampleComponent {}

if yes then from my reading of the ES6 spec seem that \2 is illegal sequence of characters for string templates so TypeScript compiler should show an error

TemplateCharacter

TemplateCharacter::
$[lookahead ≠ {]
\EscapeSequence
LineContinuation
LineTerminatorSequence
SourceCharacterbut not one of ` or \ or $ or LineTerminator

EscapeSequence

EscapeSequence::
CharacterEscapeSequence
0[lookahead ∉ DecimalDigit]
HexEscapeSequence
UnicodeEscapeSequence

CharacterEscapeSequence

CharacterEscapeSequence::
SingleEscapeCharacter
NonEscapeCharacter

SingleEscapeCharacter::one of
'"\bfnrtv

NonEscapeCharacter::
SourceCharacter but not one of EscapeCharacter or LineTerminator

EscapeCharacter::
SingleEscapeCharacter
DecimalDigit
x
u

@tandu
Copy link
Author

tandu commented Jan 17, 2016

Or as you said gulp-inline-ng2-template should replace single backslashes by two.

@blakeembrey
Copy link
Contributor

Yes. Sounds like TypeScript could give a compiler error on the escape sequence, and that'll make the issue more obvious to consumers. Need to make sure gulp-inline-ng2-template is treating the strings correctly when putting it inline (E.g. backslashes, new lines, etc.)

@DanielRosenwasser
Copy link
Member

@vladima is correct. I think #396 is either strongly related, or this is a duplicate of it. Either way, the fix for this should fix #396 as well.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Sep 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 29, 2016

This looks fixed in latest.

@mhegazy mhegazy closed this as completed Sep 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

7 participants