{"action":"closed","issue":{"url":"https://api.github.com/repos/marijnh/acorn/issues/291","labels_url":"https://api.github.com/repos/marijnh/acorn/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/marijnh/acorn/issues/291/comments","events_url":"https://api.github.com/repos/marijnh/acorn/issues/291/events","html_url":"https://github.com/marijnh/acorn/issues/291","id":93335907,"number":291,"title":"Extract / expose string literal parsing logic","user":{"login":"jmm","id":129203,"avatar_url":"https://avatars.githubusercontent.com/u/129203?v=3","gravatar_id":"","url":"https://api.github.com/users/jmm","html_url":"https://github.com/jmm","followers_url":"https://api.github.com/users/jmm/followers","following_url":"https://api.github.com/users/jmm/following{/other_user}","gists_url":"https://api.github.com/users/jmm/gists{/gist_id}","starred_url":"https://api.github.com/users/jmm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmm/subscriptions","organizations_url":"https://api.github.com/users/jmm/orgs","repos_url":"https://api.github.com/users/jmm/repos","events_url":"https://api.github.com/users/jmm/events{/privacy}","received_events_url":"https://api.github.com/users/jmm/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-06T17:47:21Z","updated_at":"2015-07-10T23:02:54Z","closed_at":"2015-07-10T23:02:54Z","body":"Would you be open to a PR that extracts the string literal parsing as an export and / or its own module? E.g.:\r\n\r\n```js\r\nvar source = '\"use\\\\x20strict\";';\r\nrequire('acorn').parseString(source);\r\n```\r\n\r\nEssentially expose the [`readString()` method from `tokenize.js`](https://github.com/marijnh/acorn/blob/094460a1e881ca90ed535ff0cc48c27108cdeebe/src/tokenize.js#L527) for arbitrary string input and return the `out` value or a node:\r\n\r\n```js\r\n{\r\n  type: 'Literal',\r\n  raw: '\"use\\\\x20strict\";',\r\n  value: 'use strict',\r\n  loc: null\r\n}\r\n```\r\n\r\nThe motivation is for use downstream in babel (see https://github.com/babel/babel/pull/1852 and [discussion in slack](https://babeljs.slack.com/archives/development/p1435365099000847) if you like). This is related to #285 here. Currently babel's code generation will promote an innocuous input string with source like `\"use\\x20strict\";` to pragma directive output, `\"use strict\";`. To avoid this it's necessary to safely evaluate the \"original\" `node.raw` source and compare it to the current, possbily altered, `node.value`. If they are identical, then `raw` can be passed through. sebmck doesn't want to just do `require('acorn')(node.raw)` (for perf reasons I believe) and I couldn't locate a package on npm that performs this function. I believe acorn's literal parsing is exactly what's needed and I assume it's in the top 2 most robust and performant JS implementations.\r\n\r\nDo you think this would even wind up being significantly faster than `parse(source)` (on the kind of source illustrated above)?"}}