Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Update Javascript parser to recast + esprima #722

Closed
wants to merge 2 commits into from
Closed

Conversation

TimvdLippe
Copy link
Contributor

While working with document.stringify(), I discovered that comments in JS ASTs are duplicated. This seemed to be an artifact of espree. By switching to recast, this issue is fixed.This also opens the door for parsing Typescript, when benjamn/recast#424 is resolved.

There are still some outstanding issues regarding unreported malformedness, but also it seems to fail on parsing console.log() with the following error:

Analyzer _getScannedFeatures() HTML inline documents can be cloned, modified, and stringified:
     TypeError: Cannot read property 'infos' of undefined
      at Lines.Lp.charAt (node_modules/recast/lib/lines.js:283:23)
      at Lines.Lp.skipSpaces (node_modules/recast/lib/lines.js:580:38)
      at Object.util.getTrueLoc (node_modules/recast/lib/util.js:122:11)
      at node_modules/recast/lib/printer.js:1701:18
      at Array.forEach (native)
      at printStatementSequence (node_modules/recast/lib/printer.js:1691:14)
      at node_modules/recast/lib/printer.js:236:20
      at FastPath.call (node_modules/recast/lib/fast-path.js:119:16)
      at genericPrintNoParens (node_modules/recast/lib/printer.js:235:25)
      at genericPrint (node_modules/recast/lib/printer.js:164:9)
      at printRootGenerically (node_modules/recast/lib/printer.js:105:15)
      at maybeReprint (node_modules/recast/lib/printer.js:97:16)
      at print (node_modules/recast/lib/printer.js:81:16)
      at exports.printComments (node_modules/recast/lib/comments.js:324:22)
      at printWithComments (node_modules/recast/lib/printer.js:61:16)
      at print (node_modules/recast/lib/printer.js:66:20)
      at Printer.print (node_modules/recast/lib/printer.js:118:21)
      at Object.print (node_modules/recast/main.js:6:33)
      at JavaScriptDocument.stringify (lib/javascript/javascript/javascript-document.ts:169:19)
      at ParsedHtmlDocument.stringify (lib/html/html/html-document.ts:193:51)
      at Document.stringify (lib/model/model/document.ts:402:32)
      at Object.<anonymous> (lib/test/core/test/core/analyzer_test.ts:667:33)
      at Generator.next (<anonymous>)
      at fulfilled (lib/test/core/analyzer_test.js:17:58)
      at <anonymous>

I have no clue what is going on there. Modifying the test does not seem to report any other error and sadly this issue manifests in my usage of the analyzer as well.

Any pointers for fixing the last few test errors would be greatly appreciated, as I seem to be stuck on fixing them 😢

  • CHANGELOG.md has been updated

@TimvdLippe
Copy link
Contributor Author

With recent changes in Polymer Core and paper-dialogs, the comments issue has been mitigated. The analyzer document.stringify() still has problems with comments, but there are available workarounds. As this change is breaking a lot of core stuff and @justinfagnani wanted to have revisit the parser story regarding TypeScript, I am holding off with this PR for now.

@TimvdLippe TimvdLippe closed this Sep 24, 2017
@TimvdLippe TimvdLippe deleted the recast-parser branch September 24, 2017 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants