Repository navigation
Fixed: TypeScript scripts importing the same module as a global script, #2341 - #2408
Open
GermanBluefox wants to merge 5 commits into
Open
GermanBluefox wants to merge 5 commits into
GermanBluefox wants to merge 5 commits into
Conversation
Run non-global TypeScript output in a CommonJS-like scope to prevent generated import bindings from colliding with bindings from shared scripts.
Run each compiled global script in a separate CommonJS scope and publish its shared exports globally to prevent generated import-name collisions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
…2341 The wrapper of a global script now only takes the first line of the compiled source and the line after it, which is empty without the wrapper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@agross this PR takes your two commits b03172f and 25ffad0 (authorship kept), with a changed wrapper for global scripts so the line numbers in errors stay the same. Could you test the branch |
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.
Fixes the remaining case from #2341: a TypeScript script that imports the same module as a global script (or two global scripts importing the same module) failed with
Global scripts and the script itself run as one
vm.Script, and TypeScript emits the same CommonJS binding for every script that imports a module.Based on the two fix commits from @agross (fork, branch
issue-2341), authorship kept. The first two commits of that branch were not taken: they only touched stalebuild/srcoutput, andmasteralready contains a more complete fix for the typings part.Changes
wrapCompiledScriptInCommonJsScope: compiled non-global TS scripts run in their own function scope (.call(exports)).wrapCompiledGlobalScriptInCommonJsScope: every compiled global TS script gets its own scope andexportsobject. Its exports are published onglobalThisas getter/setter, so later changes to exportedletvariables stay visible.main.ts.common.compiledstays unwrapped, so the compile cache is unaffected.test/testTypeScript.js: one reproduces the error without wrapping; the others cover global + normal script, two globals plus a liveletexport, and the line numbers.Line numbers in error messages
Both wrappers keep the line numbers unchanged (checked by comparing the stack traces before and after):
:6:11:6:11:8:11:8:11globalScriptLinesis counted after the global scripts are combined, sofixLineNostill works.fixLineNodoes not correct lines inside the global part).at script.js.x:10:4, pointing at the line after the script. The frame above now readsat Object.<anonymous> (…:8:1)instead ofat …:8:1. Only cosmetic.Behaviour changes to be aware of
const/letfrom global TS scripts are now reachable as globals. Before, they only ended up onsandbox.exports."use strict"stood in the middle of the combined code and had no effect. In the other direction, a"use strict"from a leading global TS script no longer makes the following JS code strict.thisin a TS script is nowexports({}) as in real CommonJS, instead of the sandbox context.ReferenceError.Cannot redefine propertyerror (checked: the properties of the VM context stay configurable). But the order changes: withvar foo = 1in a JS global andfunction fooin a later TS global,foois now the TS function. Before, it was1.Tests
test/testTypeScript.jsandtest/testResolveTypings.js: 37 passing.Test JSintegration tests could not run locally because an ioBroker instance was already running on the machine.^13.4.0required); not related to this change.🤖 Generated with Claude Code