Skip to content

Commit

Permalink
Split patchTS and patchPY
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Nov 10, 2023
1 parent a2e4ee1 commit 012ffc7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pxtcompiler/simpledriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,31 @@ namespace pxt {
}

export function patchTS(version: string, opts: pxtc.CompileOptions) {
patchText(version, opts, ".ts");
if (!version)
return
pxt.debug(`applying TS patches relative to ${version}`)
for (let fn of Object.keys(opts.fileSystem)) {
if (fn.indexOf("/") == -1 && U.endsWith(fn, ".ts")) {
const ts = opts.fileSystem[fn]
const ts2 = pxt.patching.patchJavaScript(version, ts)
if (ts != ts2) {
pxt.debug(`applying TS patch to ${fn}`)
opts.fileSystem[fn] = ts2
}
}
}
}

export function patchPY(version: string, opts: pxtc.CompileOptions) {
patchText(version, opts, ".py");
}

export function patchText(version: string, opts: pxtc.CompileOptions, extension: string) {
if (!version)
return
pxt.debug(`applying ${extension.replace('.', '')} patches relative to ${version}`)
pxt.debug(`applying PY patches relative to ${version}`)
for (let fn of Object.keys(opts.fileSystem)) {
if (fn.indexOf("/") == -1 && U.endsWith(fn, extension)) {
if (fn.indexOf("/") == -1 && U.endsWith(fn, ".py")) {
const initial = opts.fileSystem[fn]
const patched = pxt.patching.patchPython(version, initial)
if (initial != patched) {
pxt.debug(`applying ${extension.replace('.', '')} patch to ${fn}`)
pxt.debug(`applying PY patch to ${fn}`)
opts.fileSystem[fn] = patched
}
}
Expand Down

0 comments on commit 012ffc7

Please sign in to comment.