Repository navigation
Conversation
Replaces swc and dprint-swc-ext with oxc 0.158. A small view layer like dprint-swc-ext is now in `src/ast` (parents, tokens, comments, and positions over oxc's `AstKind`), and generate.rs is split into sections under `src/generation/generate`. The Rust toolchain is updated to 1.99.1. `format_program` now takes an oxc `Program` and its tokens, and `format_parsed_source` no longer takes a syntax.
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.
Replaces swc and dprint-swc-ext with oxc 0.158, since Deno wants to switch to oxc.
This is a draft until the oxc fixes below are done. 9 spec files fail on syntax oxc can't parse yet, and those spec cases are kept as they are on main.
Changes
src/astis a small view layer like dprint-swc-ext, inlined into this repo:Nodeis oxc'sAstKind.Node, generated byscripts/generate_ast_nodes.ts(rerun it after upgrading oxc).generate.rsis split into sections undersrc/generation/generate. The formatting logic is unchanged apart from the AST access.Breaking API changes
format_programtakes an oxc&Programand the tokens from parsing withTokensParserConfig. Programs parsed elsewhere should useparsing::parse_options()and check their diagnostics withis_unsupported_syntax_errorbefore formatting.format_parsed_sourceno longer takes asyntax.dprint_swc_extre-export is removed.Behavior changes
10._1;). These now error instead of formatting. Formatting also errors whenever text other than whitespace isn't covered by a token or comment.- -1being formatted as--1.Results
tests/corpus_baselines/deno.txt).[x, ,] = it, droppingstaticfromstatic constructor(), and turningvoid yieldintovoid ;.Needed in oxc before landing
{ a = 1 }in an object literal loses the= 1. The parser recovers with "Invalid assignment in object literal", but the initializer only stays in the parser's internalcover_initialized_namestate and isn't in the AST, so formatting would drop it. It needs to be in the AST along with the recoverable error. Specs:ObjectExpression_Alland 3 cases inRange_Objects.thisas a parameter that isn't the first one (ex.function test(testing, this) {}) is a fatal error ("'this' is a reserved word that cannot be used here"). TypeScript parses it and only reports it in the type checker. Specs:ClassMethod_All,Function_All,FunctionExpression_All,FunctionExpression_PreferHanging_Never, andObjectMethod_All.[e] = 1,[f + g] = 4) are a fatal error ("Computed property names are not allowed in enums"). TypeScript parses them.TSEnumMemberNamehas no variant that can hold them, so this needs an AST change. Spec:EnumMember_All.export v from "mod"(the export default from proposal) isn't supported ("Unexpected token"). swc parsed it. Spec:Range_FileTypes_Js.is_unsupported_syntax_errorfinds the recovered errors that lose text by matching message prefixes, which breaks if oxc rewords a message. Error codes or a flag on these diagnostics would make that check reliable.