@@ -5,13 +5,7 @@ import { unicodeproperties, UNICODE_PROPERTIES } from "../UNICODE_PROPERTIES";
55import { closeEnoughQuestionMark , stringify , wagnerFischer } from "../extension" ;
66import { debouncedDiagnostics } from "../DiagnosticCollection" ;
77
8- // Can't import ECMAScript module
9- // import { optimize } from 'oniguruma-parser/optimizer';
10- let optimize : typeof import ( "oniguruma-parser/optimizer" , { with : { 'resolution-mode' : 'import' } } ) . optimize | undefined ;
11- importOnigurumaParserOptimizer ( ) ;
12- async function importOnigurumaParserOptimizer ( ) {
13- optimize = ( await import ( "oniguruma-parser/optimizer" ) ) . optimize ;
14- }
8+ import { optimize } from 'oniguruma-parser-cjs/optimizer' ;
159
1610export const metadata : vscode . CodeActionProviderMetadata = {
1711 providedCodeActionKinds : [
@@ -229,22 +223,20 @@ async function optimizeRegex(edit: vscode.WorkspaceEdit, regexNode: Node, uri: v
229223 const range = toRange ( regexNode ) ;
230224
231225 try {
232- if ( optimize ) {
233- const text : string = JSON . parse ( `"${ regexNode . text } "` ) ;
234-
235- const optimized = optimize ( text , {
236- rules : {
237- // Follow `vscode-oniguruma` which enables this Oniguruma option by default
238- captureGroup : true ,
239- allowOrphanBackrefs : true ,
240- } ,
241- } ) . pattern ;
226+ const text : string = JSON . parse ( `"${ regexNode . text } "` ) ;
242227
243- const replacedText = JSON . stringify ( optimized ) . slice ( 1 , - 1 ) ; // remove surrounding "double quotes"
244- edit . replace ( uri , range , replacedText ) ;
228+ const optimized = optimize ( text , {
229+ rules : {
230+ // Follow `vscode-oniguruma` which enables this Oniguruma option by default
231+ captureGroup : true ,
232+ allowOrphanBackrefs : true ,
233+ } ,
234+ } ) . pattern ;
245235
246- return ;
247- }
236+ const replacedText = JSON . stringify ( optimized ) . slice ( 1 , - 1 ) ; // remove surrounding "double quotes"
237+ edit . replace ( uri , range , replacedText ) ;
238+
239+ return ;
248240 } catch ( error ) {
249241 console . warn ( "JSON TextMate: oniguruma-parser/optimizer: range: " , range , '\n' , error ) ;
250242 }
0 commit comments