Skip to content

fix(es/parser): Reset ctx for cond while parsing a stmt #7232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ impl<'a, I: Tokens> Parser<I> {
return self.handle_import_export(top_level, decorators);
}

self.parse_stmt_internal(start, include_decl, top_level, decorators)
let ctx = Context {
will_expect_colon_for_cond: false,
..self.ctx()
};
self.with_ctx(ctx)
.parse_stmt_internal(start, include_decl, top_level, decorators)
.map(From::from)
}

Expand Down
34 changes: 34 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/vercel/web-875/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


export async function postProcessHTML(
) {
const postProcessors: Array<PostProcessorFunction> = [
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode
? async (html: string) => {
const optimizeAmp = require('./optimize-amp')
.default as typeof import('./optimize-amp').default
html = await optimizeAmp!(html, renderOpts.ampOptimizerConfig)
if (!renderOpts.ampSkipValidation && renderOpts.ampValidator) {
await renderOpts.ampValidator(html, pathname)
}
return html
}
: null,
process.env.NEXT_RUNTIME !== 'edge' && renderOpts.optimizeFonts
? async (html: string) => {
const getFontDefinition = (url: string): string => {
}
}
: null,
process.env.NEXT_RUNTIME !== 'edge' && renderOpts.optimizeCss
? async (html: string) => {
}
: null,
inAmpMode || hybridAmp
? (html: string) => {
return html.replace(/&amp;amp=1/g, '&amp=1')
}
: null,
].filter(nonNullable)

}
Loading