add ast-dump subcommand and parser parity tests#76
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add ast-dump subcommand and parser parity tests
Summary
Add
ast-dumpsubcommand to both JS and native compilers that dumps the parsed AST as JSON. This enables direct comparison of parser output between the TypeScript and native implementations.Also fix JSON.stringify to handle type assertions by unwrapping the inner expression before stringification.
Changes
New Features
chad buildand./.build/chadthat takes a source file and outputs its AST as JSONsrc/chad-node.ts): UsesparseWithTSAPIfromparser-tssrc/chad-native.ts): UsesparseFileToASTexported fromnative-compiler-lib.tstests/ast-parity.test.ts): Auto-generated test that compares ASTs from both parsersBug Fixes
src/codegen/stdlib/json.ts): Unwrap type assertions before stringification so thatJSON.stringify(x as MyType)correctly stringifies the inner expressionBuild/Test
npm run test:parityscript to run parser parity testsFiles Changed
package.json- Addedtest:paritynpm scriptsrc/chad-node.ts- Added ast-dump subcommand and handlersrc/chad-native.ts- Added ast-dump subcommand and handlersrc/native-compiler-lib.ts- AddedparseFileToAST()export with manual JSON construction for native codesrc/codegen/stdlib/json.ts- Fix type assertion handling in stringifytests/ast-parity.test.ts- New parser parity test suitetests/fixtures/builtins/json-stringify-mixed-vars.ts- Test fixturetests/fixtures/builtins/json-stringify-type-assertion.ts- Test fixtureTest Plan
npm run test:parityto verify parser outputs matchnpm testto verify all unit tests passnpm run verify:quickto verify self-hosting works