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

Regression related to unicode identifiers #1479

Closed
rhurmala opened this issue Sep 19, 2015 · 3 comments
Closed

Regression related to unicode identifiers #1479

rhurmala opened this issue Sep 19, 2015 · 3 comments

Comments

@rhurmala
Copy link

Compiler generates string literals with octal escapes when record labels contain international characters and at the same time are not valid javascript identifiers. In most parts the compiler uses hexadecimal escapes which do not cause runtime errors.

psc version 0.7.4.1

The following works:

import Prelude
import Data.Generic
import Control.Monad.Eff.Console

newtype Asgård = Asgård { "asgård" :: String }

derive instance asgårdGeneric :: Generic Asgård

main = log $ gShow $ Asgård { "asgård": "asgård" }

related part from compiled typeclass js

return {
  asgård: asgård_1
};

This fails however:

import Prelude
import Data.Generic
import Control.Monad.Eff.Console

newtype Asgård = Asgård { "asgård-a" :: String }

derive instance asgårdGeneric :: Generic Asgård

main = log $ gShow $ Asgård { "asgård-a": "asgård" }

related js

return {
  "asg\229rd-a": asgård$minusa_1
};
pulp run

using node 0.12 results in

SyntaxError: Octal literals are not allowed in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at [eval]:1:1
    at Object.exports.runInThisContext (vm.js:74:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
@michaelficarra
Copy link
Contributor

Wow, yeah we should stop using octal escapes anywhere we are using them.

@paf31 paf31 added this to the 0.8.0 milestone Sep 21, 2015
@paf31
Copy link
Contributor

paf31 commented Nov 16, 2015

There seem to be three remaining changes needed to fix this:

  • Generic deriving shouldn't use record field names as function argument names.
  • Accessors containing invalid characters like å here, should be wrapped in quotes (foo["asgård"], not foo.asgård)
  • The same for object literals ({ "asgård": bar })

Added the easy label. Anyone care to take this? If not, I'll work on it.

@paf31 paf31 self-assigned this Nov 18, 2015
@paf31
Copy link
Contributor

paf31 commented Nov 20, 2015

Ok, scratch that, the issue is that the generated JS is not encoded as UTF-8.

@paf31 paf31 changed the title Octal literals in derived Generic typeclass instances crash program in strict mode Regression related to unicode identifiers Nov 20, 2015
@paf31 paf31 closed this as completed in 85a46e1 Nov 21, 2015
paf31 added a commit that referenced this issue Nov 21, 2015
Fix #1479, encode .js files as UTF8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants