-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Basic TypeScript Support #84
Changes from 8 commits
1f5ed9f
2d81326
eb70efb
1afb09f
ef5d3e5
6328126
2c81dc8
2311331
8ceaeee
f40f531
6672255
3c82387
750daf8
744569e
a39a885
d02860e
87dff0e
9d6fce2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ coverage | |
dist | ||
lib | ||
!test/**/node_modules | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const JSAsset = require('./JSAsset'); | ||
const localRequire = require('../utils/localRequire'); | ||
|
||
class TypeScriptAsset extends JSAsset { | ||
async transform() { | ||
this.ast = await this.parse(this.contents); | ||
this.isAstDirty = true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method shouldn't be necessary, and overriding it here disables other transforms like babel (post typescript) if needed, and uglify. |
||
|
||
async parse(code) { | ||
// require typescript, installed locally in the app | ||
let typescript = localRequire('typescript', this.name); | ||
|
||
let parserOptions = { | ||
module: typescript.ModuleKind.CommonJS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might need to add |
||
} | ||
|
||
// Transpile Module using TypeScript and parse result as ast format through babylon | ||
return await super.parse(typescript.transpileModule(code, parserOptions).outputText); | ||
} | ||
} | ||
|
||
module.exports = TypeScriptAsset; |
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.
could you add
tsx
as wellThere 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.
done