-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat(bundle-source): Support TypeScript type erasure #2627
Conversation
d6ce6de
to
f156aea
Compare
18f730e
to
6b08628
Compare
f156aea
to
ff2ec1b
Compare
packages/bundle-source/README.md
Outdated
This will also not function properly for TypeScript modules that generate | ||
JavaScript runtime code, like enums. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"enums" aren't necessarily TypeScript. (JSDoc has @enum
).
This will also not function properly for TypeScript modules that generate | |
JavaScript runtime code, like enums. | |
This will also not function properly for TypeScript modules that have [runtime impacting syntax](https://github.com/bloomberg/ts-blank-space/blob/main/docs/unsupported_syntax.md), such as `enum`. |
t.is(bundle.moduleFormat, 'endoScript'); | ||
const { source } = bundle; | ||
const compartment = new Compartment(); | ||
const ns = compartment.evaluate(source); | ||
t.is(ns.meaning, 42); | ||
}); | ||
|
||
test('endo script format supports typescript type erasure', async t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need more test cases to help make clear what to expect.
IIUC this these work:
// tsFromTs.ts
export { fortune } from './fortune.ts
// tsFromJs.ts
export { meaning } from './meaning.js
And this won't,
// jsFromTs.js
export { fortune } from './fortune.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve posted tests alongside these that verify that the full cross-product of {js,ts} can import and export {js,ts}, and also an expected failing test that you can’t import 'fortune.js'
in TypeScript, if there is no fortune.js
, even if there is fortune.ts
.
ff2ec1b
to
db2ad9a
Compare
6b08628
to
5f345d5
Compare
db2ad9a
to
b1719f8
Compare
5f345d5
to
06c3b19
Compare
b1719f8
to
60b295c
Compare
fe0022a
to
2296b4f
Compare
60b295c
to
300f46c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫶
300f46c
to
389de7b
Compare
2296b4f
to
6203ef4
Compare
6203ef4
to
91caef7
Compare
Closes: #2415
Description
This change introduces support for TypeScript through type-erasure, using ts-blank-space, which converts type annotations to equivalent blank space. As is consistent with
node --experimental-strip-types
, this only applies to modules with the.ts
,.mts
, or.cts
extensions in packages that are not undernode_modules
, to discourage publishing TypeScript as a source language to npm.Security Considerations
The choice of
ts-blank-space
is intended to minimize runtime behavior difference between TypeScript and JavaScript, such that a reviewer or a debugger of the generated JavaScript aligns with the expected behavior and original text, to the extent that is possible. This should compose well with #2444.Scaling Considerations
None.
Documentation Considerations
Contains README and NEWS.
Testing Considerations
Contains spot check tests for TypeScript in the endoScript and endoZipBase64 formats. We stand on much more rigorous testing of the underlying workspace-language-for-extension feature in Compartment Mapper #2625.
Compatibility Considerations
This does not break any prior usage.
Upgrade Considerations
None.