@exercode/problem-utils 1.11.3 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/removeCommentsInSourceCode.cjs +1 -1
- package/dist/helpers/removeCommentsInSourceCode.cjs.map +1 -1
- package/dist/helpers/removeCommentsInSourceCode.d.ts +5 -1
- package/dist/helpers/removeCommentsInSourceCode.js +1 -1
- package/dist/helpers/removeCommentsInSourceCode.js.map +1 -1
- package/dist/helpers/sourceCodeGrammars.cjs +2 -0
- package/dist/helpers/sourceCodeGrammars.cjs.map +1 -0
- package/dist/helpers/sourceCodeGrammars.d.ts +2 -0
- package/dist/helpers/sourceCodeGrammars.js +2 -0
- package/dist/helpers/sourceCodeGrammars.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/package.json +5 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../_virtual/_rollupPluginBabelHelpers.cjs");
|
|
1
|
+
"use strict";var e=require("../_virtual/_rollupPluginBabelHelpers.cjs");function n(n,i,a,u){var c,f;if(void 0===u&&(u=function(n){var r,l,i,s;return[].concat(e.toConsumableArray(null!=(r=null==(l=n.comments)?void 0:l.map(function(e){var n;return{closeRegExp:t(null!=(n=e.close)?n:/(?=\n)/g),isComment:!0,openRegExp:t(e.open)}}))?r:[]),e.toConsumableArray(null!=(i=null==(s=n.strings)?void 0:s.map(function(e){return{closeRegExp:t(e.close),isComment:!1,openRegExp:t(e.open)}}))?i:[]))}(n)),!(null!=(c=n.comments)&&c.length||a.removeStrings&&null!=(f=n.strings)&&f.length))return i;for(var g=[],m=0;m<i.length;){var h,v=void 0,x=e.createForOfIteratorHelper(u);try{for(x.s();!(h=x.n()).done;){var d=h.value,p=d.openRegExp;p.lastIndex=m;var S=p.exec(i);S&&r(S,d,v,a)&&(v={grammar:d,match:S})}}catch(e){x.e(e)}finally{x.f()}if(v){var E=v.match.index;if(!v.grammar.isComment&&a.removeStrings&&(E=s(i,v.match.index)),g.push(i.slice(m,E)),v.grammar.isComment){var R=v.grammar.closeRegExp;R.lastIndex=v.match.index+v.match[0].length;var C=R.exec(i);m=C?C.index+C[0].length:i.length}else{m=l(i,v.match.index,v.grammar);var I=i.slice(v.match.index,m);a.removeStrings?g.push(o(n,u,i,v.match.index,I)):g.push(I)}}else g.push(i.slice(m)),m=i.length}return g.join("")}function r(e,n,r,t){return!r||(e.index<r.match.index||!(e.index>r.match.index)&&(t.removeStrings&&r.grammar.isComment&&!n.isComment))}function t(e){return new RegExp(e,e.flags.includes("g")?e.flags:"".concat(e.flags,"g"))}function l(e,n,r){if("`"===e[n])return function(e,n){var r=n+1;for(;r<e.length;)if("\\"!==e[r]){if("`"===e[r])return r+1;"$"!==e[r]||"{"!==e[r+1]?r+=1:r=c(e,r+2,"}",{slashStartsRegExp:!0}).endIndex+1}else r+=2;return e.length}(e,n);if(u(e,n))return function(e,n){var r=i(e,n),t=n+r.length;for(;t<e.length;){if(e.startsWith(r,t))return t+r.length;"{"!==e[t]||"{"!==e[t+1]?"{"!==e[t]?t+="\\"===e[t]?2:1:t=c(e,t+1,"}",{slashStartsRegExp:!1}).endIndex+1:t+=2}return e.length}(e,n);var t=r.closeRegExp;t.lastIndex=n+1;var l=t.exec(e);return l?l.index+l[0].length:e.length}function i(e,n){var r,t=e.slice(n,n+3);return"'''"===t||'"""'===t?t:null!=(r=e[n])?r:""}function s(e,n){var r=a(e,n);return r?n-r.length:n}function a(e,n){var r;if('"'===e[n]||"'"===e[n]){for(var t=n-1;t>=0&&/[A-Za-z]/.test(null!=(l=e[t])?l:"");){var l;t-=1}var i=e.slice(t+1,n);if(i&&/^[bfru]+$/i.test(i)&&!(t>=0&&/[\dA-Za-z_]/.test(null!=(r=e[t])?r:"")))return i}}function o(e,r,t,l,s){return s.startsWith("`")?function(e,r,t){var l=[],i=1;for(;i<t.length-1;)if("\\"!==t[i])if("$"!==t[i]||"{"!==t[i+1])i+=1;else{var s=c(t,i+2,"}",{slashStartsRegExp:!0});l.push(n(e,s.content,{removeStrings:!0},r)),i=s.endIndex+1}else i+=2;return l.join("\n")}(e,r,s):u(t,l)?function(e,r,t){var l=i(t,0).length,s=[],a=l;for(;a<t.length-l;)if("{"!==t[a]||"{"!==t[a+1])if("{"!==t[a])a+="\\"===t[a]?2:1;else{var o=c(t,a+1,"}",{slashStartsRegExp:!1});s.push(n(e,o.content,{removeStrings:!0},r)),a=o.endIndex+1}else a+=2;return s.join("\n")}(e,r,s):""}function u(e,n){var r,t;return null!=(r=null==(t=a(e,n))?void 0:t.toLowerCase().includes("f"))&&r}function c(e,n,r,t){for(var l=1,i=n;i<e.length;){var s=e[i];if('"'!==s&&"'"!==s&&"`"!==s)if(t.slashStartsRegExp&&"/"===e[i]&&"/"===e[i+1])i=m(e,i);else if(t.slashStartsRegExp&&"/"===e[i]&&"*"===e[i+1])i=h(e,i);else if(t.slashStartsRegExp&&"/"===s)i=g(e,i);else{if("{"===s&&(l+=1),s===r&&0===(l-=1))return{content:e.slice(n,i),endIndex:i};i+=1}else i=f(e,i)}return{content:e.slice(n),endIndex:e.length}}function f(e,n){for(var r=i(e,n),t=n+r.length;t<e.length;)if("\\"!==e[t]){if(e.startsWith(r,t))return t+r.length;t+=1}else t+=2;return t}function g(e,n){for(var r=n+1,t=!1;r<e.length;)if("\\"!==e[r]){if("["===e[r]&&(t=!0),"]"===e[r]&&(t=!1),"/"===e[r]&&!t){for(r+=1;/[A-Za-z]/.test(null!=(l=e[r])?l:"");){var l;r+=1}return r}if("\n"===e[r])return n+1;r+=1}else r+=2;return n+1}function m(e,n){var r=e.indexOf("\n",n+2);return-1===r?e.length:r}function h(e,n){var r=e.indexOf("*/",n+2);return-1===r?e.length:r+2}exports.removeCommentsAndStringsInSourceCode=function(e,r){return n(e,r,{removeStrings:!0})},exports.removeCommentsInSourceCode=function(e,r){return n(e,r,{removeStrings:!1})};
|
|
2
2
|
//# sourceMappingURL=removeCommentsInSourceCode.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeCommentsInSourceCode.cjs","sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport function removeCommentsInSourceCode(\n grammer: NonNullable<LanguageDefinition['grammer']>,\n sourceCode: string\n): string {\n if (!grammer.comments?.length) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { match: RegExpExecArray; closeRegExp: RegExp | undefined; isComment: boolean } | undefined;\n\n for (const commentOrStringGrammer of [\n ...grammer.comments.map((v) => ({ isComment: true, ...v })),\n ...(grammer.strings?.map((v) => ({ isComment: false, ...v })) ?? []),\n ]) {\n const startRegExp = new RegExp(commentOrStringGrammer.open, 'g');\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && (!first || match.index < first.match.index)) {\n first = { match, closeRegExp: commentOrStringGrammer.close, isComment: commentOrStringGrammer.isComment };\n }\n }\n\n if (first) {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, first.match.index));\n\n const closeRegExp = new RegExp(first.closeRegExp ?? /(?=\\n)/g, 'g');\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n if (!first.isComment) newSourceCodeSlices.push(sourceCode.slice(first.match.index, lastIndex));\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n"],"names":["grammer","sourceCode","_grammer$comments","comments","length","newSourceCodeSlices","lastIndex","first","_i","_arr","concat","_toConsumableArray","map","v","_objectSpread","isComment","_grammer$strings$map","_grammer$strings","strings","commentOrStringGrammer","startRegExp","RegExp","open","match","exec","index","closeRegExp","close","_first$closeRegExp","push","slice","join"],"mapp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oBwB,KAAK5B,EAAW6B,MAAMxB,IAC1CA,EAAYL,EAAWG,MAE3B,CAEA,OAAOC,EAAoB0B,KAAK,GAClC"}
|
|
1
|
+
{"version":3,"file":"removeCommentsInSourceCode.cjs","sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: { slashStartsRegExp: boolean }\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '/') {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '*') {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"names":["removeCommentsAndMaybeStringsInSourceCode","grammar","sourceCode","options","commentOrStringGrammars","_grammar$comments","_grammar$strings","_grammar$comments$map","_grammar$comments2","_grammar$strings$map","_grammar$strings2","concat","_toConsumableArray","comments","map","v","_v$close","closeRegExp","makeGlobalRegExp","close","isComment","openRegExp","open","strings","compileCommentOrStringGrammars","length","removeStrings","newSourceCodeSlices","lastIndex","_step","first","_iterator","_createForOfIteratorHelper","s","n","done","commentOrStringGrammer","value","startRegExp","match","exec","shouldPreferMatch","err","e","f","stringPrefixStartIndex","index","getPythonStringPrefixStartIndex","push","slice","findStringEndIndex","stringLiteral","preserveStringInterpolationExpressions","join","regExp","RegExp","flags","includes","stringStartIndex","readBalancedExpression","slashStartsRegExp","endIndex","findJavaScriptTemplateEndIndex","hasPythonFStringPrefix","quote","getStringQuote","startsWith","findPythonFStringEndIndex","_sourceCode$stringSta","threeCharacterQuote","prefix","getPythonStringPrefix","_sourceCode$index2","test","_sourceCode$index","expressions","expression","content","preserveJavaScriptTemplateExpressions","quoteLength","preservePythonFStringExpressions","_getPythonStringPrefi","_getPythonStringPrefi2","toLowerCase","startIndex","closeChar","depth","char","skipJavaScriptSingleLineComment","skipJavaScriptBlockComment","skipJavaScriptRegExpLiteral","skipQuotedSpan","inCharacterClass","_sourceCode$index3","newLineIndex","indexOf"],"mappings":"wEAoBA,SAASA,EACPC,EACAC,EACAC,EACAC,GACQ,IAAAC,EAAAC,EACR,QAFuB,IAAvBF,IAAAA,EA8DF,SAAwCH,GAA+D,IAAAM,EAAAC,EAAAC,EAAAC,EACrG,MAAA,GAAAC,OAAAC,EAAAA,yBAAAL,EACsB,OADtBC,EACMP,EAAQY,eAAQ,EAAhBL,EAAkBM,IAAI,SAACC,GAAC,IAAAC,EAAA,MAAM,CAChCC,YAAaC,EAAwB,OAARF,EAACD,EAAEI,OAAKH,EAAI,WACzCI,WAAW,EACXC,WAAYH,EAAiBH,EAAEO,MAChC,IAAEf,EAAI,IAAEK,EAAAA,kBAKN,OALMH,EACU,OADVC,EACLT,EAAQsB,cAAO,EAAfb,EAAiBI,IAAI,SAACC,GAAC,MAAM,CAC/BE,YAAaC,EAAiBH,EAAEI,OAChCC,WAAW,EACXC,WAAYH,EAAiBH,EAAEO,MAChC,IAAEb,EAAI,IAEX,CA3E4Be,CAA+BvB,MAEpC,OAAjBI,EAACJ,EAAQY,WAARR,EAAkBoB,QAAYtB,EAAQuB,eAAiC,OAAhBpB,EAACL,EAAQsB,UAARjB,EAAiBmB,QAAS,OAAOvB,EAM9F,IAJA,IAAMyB,EAAgC,GAElCC,EAAY,EAETA,EAAY1B,EAAWuB,QAAQ,CACpC,IAE4DI,EAFxDC,OAA8E,EAACC,EAAAC,EAAAA,0BAE9C5B,GAAuB,IAA5D,IAAA2B,EAAAE,MAAAJ,EAAAE,EAAAG,KAAAC,MAA8D,CAAA,IAAnDC,EAAsBP,EAAAQ,MACzBC,EAA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ACA,GAA0B,OAAtB5C,EAAW4C,GAAiB,OAAOsC,EAAa,EACpDtC,GAAS,CATT,MAFEA,GAAS,EAcb,OAAOsC,EAAa,CACtB,CAEA,SAASI,EAAgCtF,EAAoBkF,GAC3D,IAAMU,EAAe5F,EAAW6F,QAAQ,KAAMX,EAAa,GAC3D,OAAwB,IAAjBU,EAAsB5F,EAAWuB,OAASqE,CACnD,CAEA,SAASL,EAA2BvF,EAAoBkF,GACtD,IAAMvB,EAAW3D,EAAW6F,QAAQ,KAAMX,EAAa,GACvD,OAAoB,IAAbvB,EAAkB3D,EAAWuB,OAASoC,EAAW,CAC1D,8CA5VO,SAA8C5D,EAA4BC,GAC/E,OAAOF,EAA0CC,EAASC,EAAY,CAAEwB,eAAe,GACzF,qCAPO,SAAoCzB,EAA4BC,GACrE,OAAOF,EAA0CC,EAASC,EAAY,CAAEwB,eAAe,GACzF"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { LanguageDefinition } from '../types/language.js';
|
|
2
|
-
export
|
|
2
|
+
export type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;
|
|
3
|
+
/** Removes comments from source code according to the provided language grammar. */
|
|
4
|
+
export declare function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string;
|
|
5
|
+
/** Removes comments and string literal contents while preserving executable interpolation expressions. */
|
|
6
|
+
export declare function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createForOfIteratorHelper as e,toConsumableArray as n}from"../_virtual/_rollupPluginBabelHelpers.js";function r(e,n){return l(e,n,{removeStrings:!1})}function t(e,n){return l(e,n,{removeStrings:!0})}function l(r,t,l,o){var f,c;if(void 0===o&&(o=function(e){var r,t,l,i;return[].concat(n(null!=(r=null==(t=e.comments)?void 0:t.map(function(e){var n;return{closeRegExp:s(null!=(n=e.close)?n:/(?=\n)/g),isComment:!0,openRegExp:s(e.open)}}))?r:[]),n(null!=(l=null==(i=e.strings)?void 0:i.map(function(e){return{closeRegExp:s(e.close),isComment:!1,openRegExp:s(e.open)}}))?l:[]))}(r)),!(null!=(f=r.comments)&&f.length||l.removeStrings&&null!=(c=r.strings)&&c.length))return t;for(var h=[],m=0;m<t.length;){var v,x=void 0,d=e(o);try{for(d.s();!(v=d.n()).done;){var p=v.value,E=p.openRegExp;E.lastIndex=m;var R=E.exec(t);R&&i(R,p,x,l)&&(x={grammar:p,match:R})}}catch(e){d.e(e)}finally{d.f()}if(x){var S=x.match.index;if(!x.grammar.isComment&&l.removeStrings&&(S=u(t,x.match.index)),h.push(t.slice(m,S)),x.grammar.isComment){var I=x.grammar.closeRegExp;I.lastIndex=x.match.index+x.match[0].length;var C=I.exec(t);m=C?C.index+C[0].length:t.length}else{m=a(t,x.match.index,x.grammar);var j=t.slice(x.match.index,m);l.removeStrings?h.push(g(r,o,t,x.match.index,j)):h.push(j)}}else h.push(t.slice(m)),m=t.length}return h.join("")}function i(e,n,r,t){return!r||(e.index<r.match.index||!(e.index>r.match.index)&&(t.removeStrings&&r.grammar.isComment&&!n.isComment))}function s(e){return new RegExp(e,e.flags.includes("g")?e.flags:"".concat(e.flags,"g"))}function a(e,n,r){if("`"===e[n])return function(e,n){var r=n+1;for(;r<e.length;)if("\\"!==e[r]){if("`"===e[r])return r+1;"$"!==e[r]||"{"!==e[r+1]?r+=1:r=h(e,r+2,"}",{slashStartsRegExp:!0}).endIndex+1}else r+=2;return e.length}(e,n);if(c(e,n))return function(e,n){var r=o(e,n),t=n+r.length;for(;t<e.length;){if(e.startsWith(r,t))return t+r.length;"{"!==e[t]||"{"!==e[t+1]?"{"!==e[t]?t+="\\"===e[t]?2:1:t=h(e,t+1,"}",{slashStartsRegExp:!1}).endIndex+1:t+=2}return e.length}(e,n);var t=r.closeRegExp;t.lastIndex=n+1;var l=t.exec(e);return l?l.index+l[0].length:e.length}function o(e,n){var r,t=e.slice(n,n+3);return"'''"===t||'"""'===t?t:null!=(r=e[n])?r:""}function u(e,n){var r=f(e,n);return r?n-r.length:n}function f(e,n){var r;if('"'===e[n]||"'"===e[n]){for(var t=n-1;t>=0&&/[A-Za-z]/.test(null!=(l=e[t])?l:"");){var l;t-=1}var i=e.slice(t+1,n);if(i&&/^[bfru]+$/i.test(i)&&!(t>=0&&/[\dA-Za-z_]/.test(null!=(r=e[t])?r:"")))return i}}function g(e,n,r,t,i){return i.startsWith("`")?function(e,n,r){var t=[],i=1;for(;i<r.length-1;)if("\\"!==r[i])if("$"!==r[i]||"{"!==r[i+1])i+=1;else{var s=h(r,i+2,"}",{slashStartsRegExp:!0});t.push(l(e,s.content,{removeStrings:!0},n)),i=s.endIndex+1}else i+=2;return t.join("\n")}(e,n,i):c(r,t)?function(e,n,r){var t=o(r,0).length,i=[],s=t;for(;s<r.length-t;)if("{"!==r[s]||"{"!==r[s+1])if("{"!==r[s])s+="\\"===r[s]?2:1;else{var a=h(r,s+1,"}",{slashStartsRegExp:!1});i.push(l(e,a.content,{removeStrings:!0},n)),s=a.endIndex+1}else s+=2;return i.join("\n")}(e,n,i):""}function c(e,n){var r,t;return null!=(r=null==(t=f(e,n))?void 0:t.toLowerCase().includes("f"))&&r}function h(e,n,r,t){for(var l=1,i=n;i<e.length;){var s=e[i];if('"'!==s&&"'"!==s&&"`"!==s)if(t.slashStartsRegExp&&"/"===e[i]&&"/"===e[i+1])i=x(e,i);else if(t.slashStartsRegExp&&"/"===e[i]&&"*"===e[i+1])i=d(e,i);else if(t.slashStartsRegExp&&"/"===s)i=v(e,i);else{if("{"===s&&(l+=1),s===r&&0===(l-=1))return{content:e.slice(n,i),endIndex:i};i+=1}else i=m(e,i)}return{content:e.slice(n),endIndex:e.length}}function m(e,n){for(var r=o(e,n),t=n+r.length;t<e.length;)if("\\"!==e[t]){if(e.startsWith(r,t))return t+r.length;t+=1}else t+=2;return t}function v(e,n){for(var r=n+1,t=!1;r<e.length;)if("\\"!==e[r]){if("["===e[r]&&(t=!0),"]"===e[r]&&(t=!1),"/"===e[r]&&!t){for(r+=1;/[A-Za-z]/.test(null!=(l=e[r])?l:"");){var l;r+=1}return r}if("\n"===e[r])return n+1;r+=1}else r+=2;return n+1}function x(e,n){var r=e.indexOf("\n",n+2);return-1===r?e.length:r}function d(e,n){var r=e.indexOf("*/",n+2);return-1===r?e.length:r+2}export{t as removeCommentsAndStringsInSourceCode,r as removeCommentsInSourceCode};
|
|
2
2
|
//# sourceMappingURL=removeCommentsInSourceCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeCommentsInSourceCode.js","sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport function removeCommentsInSourceCode(\n grammer: NonNullable<LanguageDefinition['grammer']>,\n sourceCode: string\n): string {\n if (!grammer.comments?.length) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { match: RegExpExecArray; closeRegExp: RegExp | undefined; isComment: boolean } | undefined;\n\n for (const commentOrStringGrammer of [\n ...grammer.comments.map((v) => ({ isComment: true, ...v })),\n ...(grammer.strings?.map((v) => ({ isComment: false, ...v })) ?? []),\n ]) {\n const startRegExp = new RegExp(commentOrStringGrammer.open, 'g');\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && (!first || match.index < first.match.index)) {\n first = { match, closeRegExp: commentOrStringGrammer.close, isComment: commentOrStringGrammer.isComment };\n }\n }\n\n if (first) {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, first.match.index));\n\n const closeRegExp = new RegExp(first.closeRegExp ?? /(?=\\n)/g, 'g');\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n if (!first.isComment) newSourceCodeSlices.push(sourceCode.slice(first.match.index, lastIndex));\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n"],"names":["removeCommentsInSourceCode","grammer","sourceCode","_grammer$comments","comments","length","newSourceCodeSlices","lastIndex","first","_i","_arr","concat","_toConsumableArray","map","v","_objectSpread","isComment","_grammer$strings$map","_grammer$strings","strings","commentOrStringGrammer","startRegExp","RegExp","open","match","exec","index","closeRegExp","close","_first$closeRegExp","push","slice","join"],"mappings":"gGAEO,SAASA,EACdC,EACAC,GACQ,IAAAC,EACR,GAAqB,OAAjBA,EAACF,EAAQG,YAARD,EAAkBE,OAAQ,OAAOH,EAMtC,IAJA,IAAMI,EAAgC,GAElCC,EAAY,EAETA,EAAYL,EAAWG,QAAQ,CAGpC,IAFA,IAAIG,OAAkG,EAEtGC,EAAA,EAAAC,EAAA,GAAAC,OAAAC,EACKX,EAAQG,SAASS,IAAI,SAACC,GAAC,OAAAC,EAAA,CAAQC,WAAW,GAASF,EAAC,IAAIF,EACE,OADFK,EACxC,OADwCC,EACvDjB,EAAQkB,cAAO,EAAfD,EAAiBL,IAAI,SAACC,GAAC,OAAAC,EAAA,CAAQC,WAAW,GAAUF,EAAC,IAAIG,EAAI,KAAER,EAAAC,EAAAL,OAAAI,IAClE,CAAA,IAAAQ,EAAAC,EAHQE,EAAsBV,EAAAD,GAIzBY,EAAc,IAAIC,OAAOF,EAAuBG,KAAM,KAC5DF,EAAYd,UAAYA,EAExB,IAAMiB,EAAQH,EAAYI,KAAKvB,GAE3BsB,KAAWhB,GAASgB,EAAME,MAAQlB,EAAMgB,MAAME,SAChDlB,EAAQ,CAAEgB,MAAAA,EAAOG,YAAaP,EAAuBQ,MAAOZ,UAAWI,EAAuBJ,WAElG,CAEA,GAAIR,EAAO,CAAA,IAAAqB,EACTvB,EAAoBwB,KAAK5B,EAAW6B,MAAMxB,EAAWC,EAAMgB,MAAME,QAEjE,IAAMC,EAAc,IAAIL,cAAMO,EAACrB,EAAMmB,aAAWE,EAAI,UAAW,KAC/DF,EAAYpB,UAAYC,EAAMgB,MAAME,MAAQlB,EAAMgB,MAAM,GAAGnB,OAE3D,IAAMmB,EAAQG,EAAYF,KAAKvB,GAE/BK,EAAYiB,EAAQA,EAAME,MAAQF,EAAM,GAAGnB,OAASH,EAAWG,OAC1DG,EAAMQ,WAAWV,EAAoBwB,KAAK5B,EAAW6B,MAAMvB,EAAMgB,MAAME,MAAOnB,GACrF,MACED,EAAoBwB,KAAK5B,EAAW6B,MAAMxB,IAC1CA,EAAYL,EAAWG,MAE3B,CAEA,OAAOC,EAAoB0B,KAAK,GAClC"}
|
|
1
|
+
{"version":3,"file":"removeCommentsInSourceCode.js","sources":["../../src/helpers/removeCommentsInSourceCode.ts"],"sourcesContent":["import type { LanguageDefinition } from '../types/language.js';\n\nexport type SourceCodeGrammar = NonNullable<LanguageDefinition['grammer']>;\n\n/** Removes comments from source code according to the provided language grammar. */\nexport function removeCommentsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: false });\n}\n\n/** Removes comments and string literal contents while preserving executable interpolation expressions. */\nexport function removeCommentsAndStringsInSourceCode(grammar: SourceCodeGrammar, sourceCode: string): string {\n return removeCommentsAndMaybeStringsInSourceCode(grammar, sourceCode, { removeStrings: true });\n}\n\ninterface CommentOrStringGrammar {\n closeRegExp: RegExp;\n isComment: boolean;\n openRegExp: RegExp;\n}\n\nfunction removeCommentsAndMaybeStringsInSourceCode(\n grammar: SourceCodeGrammar,\n sourceCode: string,\n options: { removeStrings: boolean },\n commentOrStringGrammars = compileCommentOrStringGrammars(grammar)\n): string {\n if (!grammar.comments?.length && (!options.removeStrings || !grammar.strings?.length)) return sourceCode;\n\n const newSourceCodeSlices: string[] = [];\n\n let lastIndex = 0;\n\n while (lastIndex < sourceCode.length) {\n let first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined;\n\n for (const commentOrStringGrammer of commentOrStringGrammars) {\n const startRegExp = commentOrStringGrammer.openRegExp;\n startRegExp.lastIndex = lastIndex;\n\n const match = startRegExp.exec(sourceCode);\n\n if (match && shouldPreferMatch(match, commentOrStringGrammer, first, options)) {\n first = { grammar: commentOrStringGrammer, match };\n }\n }\n\n if (first) {\n let stringPrefixStartIndex = first.match.index;\n if (!first.grammar.isComment && options.removeStrings) {\n stringPrefixStartIndex = getPythonStringPrefixStartIndex(sourceCode, first.match.index);\n }\n newSourceCodeSlices.push(sourceCode.slice(lastIndex, stringPrefixStartIndex));\n\n if (!first.grammar.isComment) {\n lastIndex = findStringEndIndex(sourceCode, first.match.index, first.grammar);\n const stringLiteral = sourceCode.slice(first.match.index, lastIndex);\n if (options.removeStrings) {\n newSourceCodeSlices.push(\n preserveStringInterpolationExpressions(\n grammar,\n commentOrStringGrammars,\n sourceCode,\n first.match.index,\n stringLiteral\n )\n );\n } else {\n newSourceCodeSlices.push(stringLiteral);\n }\n } else {\n const closeRegExp = first.grammar.closeRegExp;\n closeRegExp.lastIndex = first.match.index + first.match[0].length;\n\n const match = closeRegExp.exec(sourceCode);\n\n lastIndex = match ? match.index + match[0].length : sourceCode.length;\n }\n } else {\n newSourceCodeSlices.push(sourceCode.slice(lastIndex));\n lastIndex = sourceCode.length;\n }\n }\n\n return newSourceCodeSlices.join('');\n}\n\nfunction compileCommentOrStringGrammars(grammar: SourceCodeGrammar): readonly CommentOrStringGrammar[] {\n return [\n ...(grammar.comments?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close ?? /(?=\\n)/g),\n isComment: true,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ...(grammar.strings?.map((v) => ({\n closeRegExp: makeGlobalRegExp(v.close),\n isComment: false,\n openRegExp: makeGlobalRegExp(v.open),\n })) ?? []),\n ] satisfies CommentOrStringGrammar[];\n}\n\nfunction shouldPreferMatch(\n match: RegExpExecArray,\n grammar: CommentOrStringGrammar,\n first: { grammar: CommentOrStringGrammar; match: RegExpExecArray } | undefined,\n options: { removeStrings: boolean }\n): boolean {\n if (!first) return true;\n if (match.index < first.match.index) return true;\n if (match.index > first.match.index) return false;\n return options.removeStrings && first.grammar.isComment && !grammar.isComment;\n}\n\nfunction makeGlobalRegExp(regExp: RegExp): RegExp {\n return new RegExp(regExp, regExp.flags.includes('g') ? regExp.flags : `${regExp.flags}g`);\n}\n\nfunction findStringEndIndex(sourceCode: string, stringStartIndex: number, grammar: CommentOrStringGrammar): number {\n if (sourceCode[stringStartIndex] === '`') return findJavaScriptTemplateEndIndex(sourceCode, stringStartIndex);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return findPythonFStringEndIndex(sourceCode, stringStartIndex);\n\n const closeRegExp = grammar.closeRegExp;\n closeRegExp.lastIndex = stringStartIndex + 1;\n const match = closeRegExp.exec(sourceCode);\n return match ? match.index + match[0].length : sourceCode.length;\n}\n\nfunction findJavaScriptTemplateEndIndex(sourceCode: string, stringStartIndex: number): number {\n let index = stringStartIndex + 1;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '`') return index + 1;\n if (sourceCode[index] === '$' && sourceCode[index + 1] === '{') {\n index = readBalancedExpression(sourceCode, index + 2, '}', { slashStartsRegExp: true }).endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return sourceCode.length;\n}\n\nfunction findPythonFStringEndIndex(sourceCode: string, stringStartIndex: number): number {\n const quote = getStringQuote(sourceCode, stringStartIndex);\n let index = stringStartIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n if (sourceCode[index] === '{' && sourceCode[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '{') {\n index = readBalancedExpression(sourceCode, index + 1, '}', { slashStartsRegExp: false }).endIndex + 1;\n continue;\n }\n index += sourceCode[index] === '\\\\' ? 2 : 1;\n }\n\n return sourceCode.length;\n}\n\nfunction getStringQuote(sourceCode: string, stringStartIndex: number): string {\n const threeCharacterQuote = sourceCode.slice(stringStartIndex, stringStartIndex + 3);\n if (threeCharacterQuote === \"'''\" || threeCharacterQuote === '\"\"\"') return threeCharacterQuote;\n return sourceCode[stringStartIndex] ?? '';\n}\n\nfunction getPythonStringPrefixStartIndex(sourceCode: string, stringStartIndex: number): number {\n const prefix = getPythonStringPrefix(sourceCode, stringStartIndex);\n return prefix ? stringStartIndex - prefix.length : stringStartIndex;\n}\n\nfunction getPythonStringPrefix(sourceCode: string, stringStartIndex: number): string | undefined {\n if (sourceCode[stringStartIndex] !== '\"' && sourceCode[stringStartIndex] !== \"'\") return undefined;\n let index = stringStartIndex - 1;\n while (index >= 0 && /[A-Za-z]/.test(sourceCode[index] ?? '')) index -= 1;\n\n const prefix = sourceCode.slice(index + 1, stringStartIndex);\n if (!prefix || !/^[bfru]+$/i.test(prefix)) return undefined;\n if (index >= 0 && /[\\dA-Za-z_]/.test(sourceCode[index] ?? '')) return undefined;\n\n return prefix;\n}\n\nfunction preserveStringInterpolationExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n sourceCode: string,\n stringStartIndex: number,\n stringLiteral: string\n): string {\n if (stringLiteral.startsWith('`'))\n return preserveJavaScriptTemplateExpressions(grammar, commentOrStringGrammars, stringLiteral);\n if (hasPythonFStringPrefix(sourceCode, stringStartIndex))\n return preservePythonFStringExpressions(grammar, commentOrStringGrammars, stringLiteral);\n return '';\n}\n\nfunction hasPythonFStringPrefix(sourceCode: string, stringStartIndex: number): boolean {\n return getPythonStringPrefix(sourceCode, stringStartIndex)?.toLowerCase().includes('f') ?? false;\n}\n\nfunction preserveJavaScriptTemplateExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const expressions: string[] = [];\n let index = 1;\n\n while (index < stringLiteral.length - 1) {\n if (stringLiteral[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '$' && stringLiteral[index + 1] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 2, '}', { slashStartsRegExp: true });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction preservePythonFStringExpressions(\n grammar: SourceCodeGrammar,\n commentOrStringGrammars: readonly CommentOrStringGrammar[],\n stringLiteral: string\n): string {\n const quoteLength = getStringQuote(stringLiteral, 0).length;\n const expressions: string[] = [];\n let index = quoteLength;\n\n while (index < stringLiteral.length - quoteLength) {\n if (stringLiteral[index] === '{' && stringLiteral[index + 1] === '{') {\n index += 2;\n continue;\n }\n if (stringLiteral[index] === '{') {\n const expression = readBalancedExpression(stringLiteral, index + 1, '}', { slashStartsRegExp: false });\n expressions.push(\n removeCommentsAndMaybeStringsInSourceCode(\n grammar,\n expression.content,\n { removeStrings: true },\n commentOrStringGrammars\n )\n );\n index = expression.endIndex + 1;\n continue;\n }\n index += stringLiteral[index] === '\\\\' ? 2 : 1;\n }\n\n return expressions.join('\\n');\n}\n\nfunction readBalancedExpression(\n sourceCode: string,\n startIndex: number,\n closeChar: string,\n options: { slashStartsRegExp: boolean }\n): { content: string; endIndex: number } {\n let depth = 1;\n let index = startIndex;\n\n while (index < sourceCode.length) {\n const char = sourceCode[index];\n if (char === '\"' || char === \"'\" || char === '`') {\n index = skipQuotedSpan(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '/') {\n index = skipJavaScriptSingleLineComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && sourceCode[index] === '/' && sourceCode[index + 1] === '*') {\n index = skipJavaScriptBlockComment(sourceCode, index);\n continue;\n }\n if (options.slashStartsRegExp && char === '/') {\n index = skipJavaScriptRegExpLiteral(sourceCode, index);\n continue;\n }\n if (char === '{') depth += 1;\n if (char === closeChar) {\n depth -= 1;\n if (depth === 0) return { content: sourceCode.slice(startIndex, index), endIndex: index };\n }\n index += 1;\n }\n\n return { content: sourceCode.slice(startIndex), endIndex: sourceCode.length };\n}\n\nfunction skipQuotedSpan(sourceCode: string, startIndex: number): number {\n const quote = getStringQuote(sourceCode, startIndex);\n let index = startIndex + quote.length;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode.startsWith(quote, index)) return index + quote.length;\n index += 1;\n }\n\n return index;\n}\n\nfunction skipJavaScriptRegExpLiteral(sourceCode: string, startIndex: number): number {\n let index = startIndex + 1;\n let inCharacterClass = false;\n\n while (index < sourceCode.length) {\n if (sourceCode[index] === '\\\\') {\n index += 2;\n continue;\n }\n if (sourceCode[index] === '[') inCharacterClass = true;\n if (sourceCode[index] === ']') inCharacterClass = false;\n if (sourceCode[index] === '/' && !inCharacterClass) {\n index += 1;\n while (/[A-Za-z]/.test(sourceCode[index] ?? '')) index += 1;\n return index;\n }\n if (sourceCode[index] === '\\n') return startIndex + 1;\n index += 1;\n }\n\n return startIndex + 1;\n}\n\nfunction skipJavaScriptSingleLineComment(sourceCode: string, startIndex: number): number {\n const newLineIndex = sourceCode.indexOf('\\n', startIndex + 2);\n return newLineIndex === -1 ? sourceCode.length : newLineIndex;\n}\n\nfunction skipJavaScriptBlockComment(sourceCode: string, startIndex: number): number {\n const endIndex = sourceCode.indexOf('*/', startIndex + 2);\n return endIndex === -1 ? sourceCode.length : endIndex + 2;\n}\n"],"names":["removeCommentsInSourceCode","grammar","sourceCode","removeCommentsAndMaybeStringsInSourceCode","removeStrings","removeCommentsAndStringsInSourceCode","options","commentOrStringGrammars","_grammar$comments","_grammar$strings","_grammar$comments$map","_grammar$comments2","_grammar$strings$map","_grammar$strings2","concat","_toConsumableArray","comments","map","v","_v$close","closeRegExp","makeGlobalRegExp","close","isComment","openRegExp","open","strings","compileCommentOrStringGrammars","length","newSourceCodeSlices","lastIndex","_step","first","_iterator","_createForOfIteratorHelper","s","n","done","commentOrStringGrammer","value","startRegExp","match","exec","shouldPreferMatch","err","e","f","stringPrefixStartIndex","index","getPythonStringPrefixStartIndex","push","slice","findStringEndIndex","stringLiteral","preserveStringInterpolationExpressions","join","regExp","RegExp","flags","includes","stringStartIndex","readBalancedExpression","slashStartsRegExp","endIndex","findJavaScriptTemplateEndIndex","hasPythonFStringPrefix","quote","getStringQuote","startsWith","findPythonFStringEndIndex","_sourceCode$stringSta","threeCharacterQuote","prefix","getPythonStringPrefix","_sourceCode$index2","test","_sourceCode$index","expressions","expression","content","preserveJavaScriptTemplateExpressions","quoteLength","preservePythonFStringExpressions","_getPythonStringPrefi","_getPythonStringPrefi2","toLowerCase","startIndex","closeChar","depth","char","skipJavaScriptSingleLineComment","skipJavaScriptBlockComment","skipJavaScriptRegExpLiteral","skipQuotedSpan","inCharacterClass","_sourceCode$index3","newLineIndex","indexOf"],"mappings":"4GAKO,SAASA,EAA2BC,EAA4BC,GACrE,OAAOC,EAA0CF,EAASC,EAAY,CAAEE,eAAe,GACzF,CAGO,SAASC,EAAqCJ,EAA4BC,GAC/E,OAAOC,EAA0CF,EAASC,EAAY,CAAEE,eAAe,GACzF,CAQA,SAASD,EACPF,EACAC,EACAI,EACAC,GACQ,IAAAC,EAAAC,EACR,QAFuB,IAAvBF,IAAAA,EA8DF,SAAwCN,GAA+D,IAAAS,EAAAC,EAAAC,EAAAC,EACrG,MAAA,GAAAC,OAAAC,SAAAL,EACsB,OADtBC,EACMV,EAAQe,eAAQ,EAAhBL,EAAkBM,IAAI,SAACC,GAAC,IAAAC,EAAA,MAAM,CAChCC,YAAaC,EAAwB,OAARF,EAACD,EAAEI,OAAKH,EAAI,WACzCI,WAAW,EACXC,WAAYH,EAAiBH,EAAEO,MAChC,IAAEf,EAAI,IAAEK,EAKN,OALMH,EACU,OADVC,EACLZ,EAAQyB,cAAO,EAAfb,EAAiBI,IAAI,SAACC,GAAC,MAAM,CAC/BE,YA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FT,MAFEA,GAAS,EAOb,OAAOA,CACT,CAEA,SAAS4C,EAA4B1F,EAAoBoF,GAIvD,IAHA,IAAItC,EAAQsC,EAAa,EACrBQ,GAAmB,EAEhB9C,EAAQ9C,EAAW0B,QACxB,GAA0B,OAAtB1B,EAAW8C,GAAf,CAMA,GAF0B,MAAtB9C,EAAW8C,KAAgB8C,GAAmB,GACxB,MAAtB5F,EAAW8C,KAAgB8C,GAAmB,GACxB,MAAtB5F,EAAW8C,KAAmB8C,EAAkB,CAElD,IADA9C,GAAS,EACF,WAAW2B,KAAsB,OAAlBoB,EAAC7F,EAAW8C,IAAM+C,EAAI,KAAG,CAAA,IAAAA,EAAE/C,GAAS,CAAE,CAC5D,OAAOA,CACT,CACA,GAA0B,OAAtB9C,EAAW8C,GAAiB,OAAOsC,EAAa,EACpDtC,GAAS,CATT,MAFEA,GAAS,EAcb,OAAOsC,EAAa,CACtB,CAEA,SAASI,EAAgCxF,EAAoBoF,GAC3D,IAAMU,EAAe9F,EAAW+F,QAAQ,KAAMX,EAAa,GAC3D,OAAwB,IAAjBU,EAAsB9F,EAAW0B,OAASoE,CACnD,CAEA,SAASL,EAA2BzF,EAAoBoF,GACtD,IAAMvB,EAAW7D,EAAW+F,QAAQ,KAAMX,EAAa,GACvD,OAAoB,IAAbvB,EAAkB7D,EAAW0B,OAASmC,EAAW,CAC1D"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("../_virtual/_rollupPluginBabelHelpers.cjs"),r=require("../types/language.cjs"),a=Object.fromEntries(Object.entries(r.languageIdToDefinition).flatMap(function(r){var a=e.slicedToArray(r,2),t=a[0],i=a[1];return i.grammer?[[t,i.grammer]]:[]}));exports.languageIdToSourceCodeGrammar=a;
|
|
2
|
+
//# sourceMappingURL=sourceCodeGrammars.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceCodeGrammars.cjs","sources":["../../src/helpers/sourceCodeGrammars.ts"],"sourcesContent":["import type { SourceCodeGrammar } from './removeCommentsInSourceCode.js';\nimport { languageIdToDefinition } from '../types/language.js';\n\nexport const languageIdToSourceCodeGrammar = Object.fromEntries(\n Object.entries(languageIdToDefinition).flatMap(([languageId, languageDefinition]) =>\n languageDefinition.grammer ? [[languageId, languageDefinition.grammer] as const] : []\n )\n) as Readonly<Record<string, SourceCodeGrammar | undefined>>;\n"],"names":["languageIdToSourceCodeGrammar","Object","fromEntries","entries","languageIdToDefinition","flatMap","_ref","_ref2","_slicedToArray","languageId","languageDefinition","grammer"],"mappings":"2GAGaA,EAAgCC,OAAOC,YAClDD,OAAOE,QAAQC,0BAAwBC,QAAQ,SAAAC,GAAA,IAAAC,EAAAC,EAAAA,cAAAF,EAAA,GAAEG,EAAUF,EAAA,GAAEG,EAAkBH,EAAA,GAAA,OAC7EG,EAAmBC,QAAU,CAAC,CAACF,EAAYC,EAAmBC,UAAqB,EAAE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{slicedToArray as r}from"../_virtual/_rollupPluginBabelHelpers.js";import{languageIdToDefinition as e}from"../types/language.js";var a=Object.fromEntries(Object.entries(e).flatMap(function(e){var a=r(e,2),t=a[0],l=a[1];return l.grammer?[[t,l.grammer]]:[]}));export{a as languageIdToSourceCodeGrammar};
|
|
2
|
+
//# sourceMappingURL=sourceCodeGrammars.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceCodeGrammars.js","sources":["../../src/helpers/sourceCodeGrammars.ts"],"sourcesContent":["import type { SourceCodeGrammar } from './removeCommentsInSourceCode.js';\nimport { languageIdToDefinition } from '../types/language.js';\n\nexport const languageIdToSourceCodeGrammar = Object.fromEntries(\n Object.entries(languageIdToDefinition).flatMap(([languageId, languageDefinition]) =>\n languageDefinition.grammer ? [[languageId, languageDefinition.grammer] as const] : []\n )\n) as Readonly<Record<string, SourceCodeGrammar | undefined>>;\n"],"names":["languageIdToSourceCodeGrammar","Object","fromEntries","entries","languageIdToDefinition","flatMap","_ref","_ref2","_slicedToArray","languageId","languageDefinition","grammer"],"mappings":"2IAGaA,EAAgCC,OAAOC,YAClDD,OAAOE,QAAQC,GAAwBC,QAAQ,SAAAC,GAAA,IAAAC,EAAAC,EAAAF,EAAA,GAAEG,EAAUF,EAAA,GAAEG,EAAkBH,EAAA,GAAA,OAC7EG,EAAmBC,QAAU,CAAC,CAACF,EAAYC,EAAmBC,UAAqB,EAAE"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./helpers/parseArgs.cjs"),
|
|
1
|
+
"use strict";var e=require("./helpers/parseArgs.cjs"),r=require("./helpers/printTestCaseResult.cjs"),s=require("./helpers/removeCommentsInSourceCode.cjs"),t=require("./helpers/sourceCodeGrammars.cjs"),o=require("./helpers/startHttpServer.cjs"),a=require("./types/decisionCode.cjs"),p=require("./types/testCaseResult.cjs");exports.parseArgs=e.parseArgs,exports.encodeFileForTestCaseResult=r.encodeFileForTestCaseResult,exports.printTestCaseResult=r.printTestCaseResult,exports.removeCommentsAndStringsInSourceCode=s.removeCommentsAndStringsInSourceCode,exports.removeCommentsInSourceCode=s.removeCommentsInSourceCode,exports.languageIdToSourceCodeGrammar=t.languageIdToSourceCodeGrammar,exports.startHttpServer=o.startHttpServer,exports.DecisionCode=a.DecisionCode,exports.TEST_CASE_RESULT_PREFIX=p.TEST_CASE_RESULT_PREFIX,exports.testCaseResultSchema=p.testCaseResultSchema;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './helpers/parseArgs.js';
|
|
2
2
|
export * from './helpers/printTestCaseResult.js';
|
|
3
|
+
export * from './helpers/removeCommentsInSourceCode.js';
|
|
4
|
+
export * from './helpers/sourceCodeGrammars.js';
|
|
3
5
|
export * from './helpers/startHttpServer.js';
|
|
4
6
|
export * from './types/decisionCode.js';
|
|
5
7
|
export * from './types/testCaseResult.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{parseArgs}from"./helpers/parseArgs.js";export{encodeFileForTestCaseResult,printTestCaseResult}from"./helpers/printTestCaseResult.js";export{startHttpServer}from"./helpers/startHttpServer.js";export{DecisionCode}from"./types/decisionCode.js";export{TEST_CASE_RESULT_PREFIX,testCaseResultSchema}from"./types/testCaseResult.js";
|
|
1
|
+
export{parseArgs}from"./helpers/parseArgs.js";export{encodeFileForTestCaseResult,printTestCaseResult}from"./helpers/printTestCaseResult.js";export{removeCommentsAndStringsInSourceCode,removeCommentsInSourceCode}from"./helpers/removeCommentsInSourceCode.js";export{languageIdToSourceCodeGrammar}from"./helpers/sourceCodeGrammars.js";export{startHttpServer}from"./helpers/startHttpServer.js";export{DecisionCode}from"./types/decisionCode.js";export{TEST_CASE_RESULT_PREFIX,testCaseResultSchema}from"./types/testCaseResult.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exercode/problem-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": ":100: A set of utilities for judging programs on Exercode (https://exercode.willbooster.com/).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"exercode",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"prettier": "@willbooster/prettier-config",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ai-sdk/amazon-bedrock": "4.0.
|
|
54
|
-
"@ai-sdk/google": "3.0.
|
|
53
|
+
"@ai-sdk/amazon-bedrock": "4.0.104",
|
|
54
|
+
"@ai-sdk/google": "3.0.72",
|
|
55
55
|
"@ai-sdk/openai": "3.0.63",
|
|
56
56
|
"@ai-sdk/xai": "3.0.89",
|
|
57
57
|
"ai": "6.0.177",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
68
68
|
"@willbooster/oxlint-config": "1.4.6",
|
|
69
69
|
"@willbooster/prettier-config": "10.4.0",
|
|
70
|
-
"@willbooster/wb": "13.15.
|
|
70
|
+
"@willbooster/wb": "13.15.2",
|
|
71
71
|
"build-ts": "17.1.13",
|
|
72
72
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
73
73
|
"dotenv-cli": "11.0.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"oxlint-tsgolint": "0.22.1",
|
|
78
78
|
"prettier": "3.8.3",
|
|
79
79
|
"prettier-plugin-java": "2.8.1",
|
|
80
|
-
"puppeteer": "24.43.
|
|
80
|
+
"puppeteer": "24.43.1",
|
|
81
81
|
"semantic-release": "25.0.3",
|
|
82
82
|
"sort-package-json": "3.6.1",
|
|
83
83
|
"vitest": "4.1.5"
|