Skip to content

Commit

Permalink
feat: add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 31, 2021
1 parent 30f8bfa commit d27d8db
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ Enable `"@babel/preset-react"`. `true` by default.

Enable `"@babel/preset-flow"`. `true` by default.

8) `removeAllUseStrict`
7) `typescript`

Enable `"@babel/preset-typescript"`. `true` by default.

9) `removeAllUseStrict`

Remove all `'use strict'` from all files. Passed to [`babel-plugin-transform-not-strict`](https://github.com/atom-ide-community/babel-plugin-transform-not-strict#usage-remove-all). This is `false` by default.

9) `notStrictDirectiveTriggers` and `notStrictCommentTriggers`
10) `notStrictDirectiveTriggers` and `notStrictCommentTriggers`

These specify `"not strict"` triggers. Passed to [`babel-plugin-transform-not-strict`](https://github.com/atom-ide-community/babel-plugin-transform-not-strict#usage-extra-directive-or-comment-triggers).

Expand All @@ -120,6 +124,7 @@ It includes the following presets:
- `"@babel/preset-env"` (configured for `electron`)
- `"@babel/preset-react"`
- `"@babel/preset-flow"`
- `"@babel/preset-typescript"`

It also includes all the proposal plugins such as:
- `"@babel/plugin-proposal-optional-chaining"`
Expand Down
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (process.env.BABEL_KEEP_MODULES === "true") {
}

function handleOptions(options) {
let {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers } = options
let {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, typescript, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers } = options

// use Electron 5 targets by default
if (targets == null) {
Expand Down Expand Up @@ -37,6 +37,10 @@ function handleOptions(options) {
flow = true
}

if (typescript == null) {
typescript = true
}

if (removeAllUseStrict == null) {
removeAllUseStrict = false
}
Expand All @@ -47,12 +51,12 @@ function handleOptions(options) {
notStrictCommentTriggers = ['@babel', '@flow', '* @babel', '* @flow']
}

return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers }
return {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, typescript, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers }
}

module.exports = (api, options, dirname) => {

const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers } = handleOptions(options)
const {targets, keepModules, addModuleExports, addModuleExportsDefaultProperty, react, flow, typescript, removeAllUseStrict, notStrictDirectiveTriggers, notStrictCommentTriggers } = handleOptions(options)

let presets = [
[
Expand All @@ -76,6 +80,12 @@ module.exports = (api, options, dirname) => {
]);
}

if (typescript) {
presets.push(...[
require("@babel/preset-typescript"),
]);
}

let plugins = [
require("@babel/plugin-proposal-function-bind"),

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-private-methods": "7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.5",
"@babel/plugin-proposal-do-expressions": "7.12.13",
"@babel/plugin-proposal-export-default-from": "7.12.13",
Expand All @@ -35,17 +34,19 @@
"@babel/plugin-proposal-numeric-separator": "7.12.13",
"@babel/plugin-proposal-optional-chaining": "7.13.12",
"@babel/plugin-proposal-pipeline-operator": "7.12.13",
"@babel/plugin-proposal-private-methods": "7.13.0",
"@babel/plugin-proposal-throw-expressions": "7.12.13",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-import-meta": "7.10.4",
"@babel/plugin-transform-reserved-words": "^7.12.13",
"@babel/preset-env": "7.13.12",
"@babel/preset-flow": "7.13.13",
"@babel/preset-react": "7.13.13",
"@babel/preset-typescript": "^7.13.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-codegen": "^4.1.4",
"babel-plugin-preval": "^5.0.0",
"babel-plugin-transform-not-strict": "^0.3.1",
"@babel/plugin-transform-reserved-words": "^7.12.13"
"babel-plugin-transform-not-strict": "^0.3.1"
},
"peerDependencies": {
"@babel/cli": "^7",
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d27d8db

Please sign in to comment.