escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Should be using the directive estree field

Open lachrist opened this issue 4 years ago • 0 comments

There is a field in the entree spec which saves the raw value of directives: https://github.com/estree/estree/blob/master/es5.md#directive Because escodegen does not use this field, it transform invalid use-strict directives into valid ones:

const code1 = "'use\\u0020strict';";
const estree1 = require("acorn").parse(code1, {ecmaVersion:2020});
const code2 = require("escodegen").generate(estree1);
console.log(code2) // prints "'use strict';" instead of "'use\\u0020strict';"

There exists some test262s which account for that:

https://github.com/tc39/test262/blob/main/test/language/directive-prologue/14.1-5-s.js https://github.com/tc39/test262/blob/main/test/language/directive-prologue/14.1-4-s.js

Kind regards, Laurent

lachrist avatar Jan 08 '21 09:01 lachrist