Merge pull request #84 from RealKinetic/fix-phantom-comments

Fix phantom comments causing runtime exceptions
This commit is contained in:
Matthew Griffith 2022-02-06 20:07:16 -05:00 committed by GitHub
commit 9e6001b717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Upcoming
- Fix "phantom comments" issue. The sourceFile's comments were intermingling
with optimized-record output causing runtime exceptions in some cases. It's
suspected to be an issue
- Bump typescript compiler to 4.5.5
- Expose `transform: (jsSource: string) => string` JS API. Useful for build toolchains.
- Update chromedriver to work with latest version of Chrome

View File

@ -68,6 +68,6 @@
"commander": "^6.0.0",
"node-elm-compiler": "^5.0.4",
"ts-union": "^2.2.1",
"typescript": "^3.9.7"
"typescript": "^4.5.5"
}
}

View File

@ -40,7 +40,18 @@ export const transform = async (
verbose: boolean,
transforms: Transforms
): Promise<string> => {
let source = ts.createSourceFile('elm.js', jsSource, ts.ScriptTarget.ES2018);
/* First, remove comments from source.
We've encountered a bug when running some of the transforms (specifically the
record-update transform when the -O3 flag is enabled) where comments from the
source file appear interspersed throughout the transformed file. In some cases
this will result in runtime exceptions.
*/
const sourceWithComments = ts.createSourceFile('n/a', jsSource, ts.ScriptTarget.ES2018);
const noCommentsPrinter = ts.createPrinter({ removeComments: true });
const jsSourceWithoutComments = noCommentsPrinter.printFile(sourceWithComments);
let source = ts.createSourceFile('elm.js', jsSourceWithoutComments, ts.ScriptTarget.ES2018);
let parsedVariants = primitives;
if (elmfile && transforms.variantShapes) {