Skip to content

Commit

Permalink
feat: add latested proposal plugins
Browse files Browse the repository at this point in the history
1. class-properties\n2. partial-applicatio\n3. private-methods
  • Loading branch information
JounQin committed Aug 17, 2019
1 parent 1d76d84 commit a7f09da
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage
node_modules
/index.js
# Babel parse issue, ignore temporarily
test/private-methods.ts
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module.exports = {
},
},
settings: {
'import/ignore': [/test\/private-methods.ts$/],
'import/parsers': {
'@typescript-eslint/parser': [],
'babel-eslint': ['.ts'],
},
'import/resolver': {
Expand All @@ -22,6 +24,12 @@ module.exports = {
files: '*.{js,ts}',
...js,
},
{
files: '*.ts',
rules: {
'import/namespace': 0,
},
},
jest,
],
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
coverage
node_modules
CHANGELOG.md
# Not supported by Prettier yet
test/partial-application.ts
18 changes: 11 additions & 7 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const config = require('@1stg/prettier-config')

module.exports = Object.assign({}, config, {
overrides: config.overrides.concat({
files: '*.ts',
options: {
parser: 'babel',
module.exports = {
...config,
overrides: [
...config.overrides,
{
files: '*.ts',
options: {
parser: 'babel',
},
},
}),
})
],
}
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ So that you can use babel to transform proposals which are current in stage 0-2

## Enabled proposal plugins

1. [do-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-do-expressions)
2. [function-bind](https://www.npmjs.com/package/@babel/plugin-proposal-function-bind)
3. [function-sent](https://www.npmjs.com/package/@babel/plugin-proposal-function-sent)
4. [json-strings](https://www.npmjs.com/package/@babel/plugin-proposal-json-strings)
5. [logical-assignment-operators](https://www.npmjs.com/package/@babel/plugin-proposal-logical-assignment-operators)
6. [nullish-coalescing-operator](https://www.npmjs.com/package/@babel/plugin-proposal-nullish-coalescing-operator)
7. [optional-chaining](https://www.npmjs.com/package/@babel/plugin-proposal-optional-chaining)
8. [pipeline-operator](https://www.npmjs.com/package/@babel/plugin-proposal-pipeline-operator)
9. [throw-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-throw-expressions)
1. [class-properties](https://www.npmjs.com/package/@babel/plugin-proposal-class-properties)
2. [do-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-do-expressions)
3. [function-bind](https://www.npmjs.com/package/@babel/plugin-proposal-function-bind)
4. [function-sent](https://www.npmjs.com/package/@babel/plugin-proposal-function-sent)
5. [json-strings](https://www.npmjs.com/package/@babel/plugin-proposal-json-strings)
6. [logical-assignment-operators](https://www.npmjs.com/package/@babel/plugin-proposal-logical-assignment-operators)
7. [nullish-coalescing-operator](https://www.npmjs.com/package/@babel/plugin-proposal-nullish-coalescing-operator)
8. [optional-chaining](https://www.npmjs.com/package/@babel/plugin-proposal-optional-chaining)
9. [partial-application](https://www.npmjs.com/package/@babel/plugin-proposal-partial-application)
10. [pipeline-operator](https://www.npmjs.com/package/@babel/plugin-proposal-pipeline-operator)
11. [private-methods](https://www.npmjs.com/package/@babel/plugin-proposal-private-methods)
12. [throw-expressions](https://www.npmjs.com/package/@babel/plugin-proposal-throw-expressions)

## Install

```sh
npm install --save-dev babel-preset-proposal-typescript # npm
yarn add -D babel-preset-proposal-typescript # yarn
# yarn
yarn add -D babel-preset-proposal-typescript

# npm
npm i -D babel-preset-proposal-typescript
```

## Usage
Expand Down
6 changes: 6 additions & 0 deletions esm.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import syntaxDecorators from '@babel/plugin-syntax-decorators'
import syntaxDynamicImport from '@babel/plugin-syntax-dynamic-import'
import syntaxTypeScript from '@babel/plugin-syntax-typescript'
import proposalClassProperties from '@babel/plugin-proposal-class-properties'
import proposalDoExpressions from '@babel/plugin-proposal-do-expressions'
import proposalFunctionBind from '@babel/plugin-proposal-function-bind'
import proposalFunctionSent from '@babel/plugin-proposal-function-sent'
import proposalJsonStrings from '@babel/plugin-proposal-json-strings'
import proposalLogicalAssignmentOperators from '@babel/plugin-proposal-logical-assignment-operators'
import proposalNullishCoalescingOperator from '@babel/plugin-proposal-nullish-coalescing-operator'
import proposalOptionalChaining from '@babel/plugin-proposal-optional-chaining'
import proposalPartialApplication from '@babel/plugin-proposal-partial-application'
import proposalPipelineOperator from '@babel/plugin-proposal-pipeline-operator'
import proposalPrivateMethods from '@babel/plugin-proposal-private-methods'
import proposalThrowExpression from '@babel/plugin-proposal-throw-expressions'

export default () => ({
Expand All @@ -21,19 +24,22 @@ export default () => ({
],
syntaxDynamicImport,
syntaxTypeScript,
proposalClassProperties,
proposalDoExpressions,
proposalFunctionBind,
proposalFunctionSent,
proposalJsonStrings,
proposalLogicalAssignmentOperators,
proposalNullishCoalescingOperator,
proposalOptionalChaining,
proposalPartialApplication,
[
proposalPipelineOperator,
{
proposal: 'minimal',
},
],
proposalPrivateMethods,
proposalThrowExpression,
],
})
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "babel-preset-proposal-typescript",
"version": "1.1.0",
"version": "1.2.0",
"description": "Yet another Babel preset for TypeScript, only transforms proposals which TypeScript does not support now.",
"module": "esm.js",
"repository": "git@github.com/JounQin/babel-preset-proposal-typescript.git",
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"scripts": {
"build": "babel --no-babelrc --presets @babel/env esm.js > index.js",
"build": "babel --presets @babel/env esm.js > index.js",
"lint": "EFF_NO_LINK_RULES=true eslint . --ext .js,.ts -f friendly",
"pretest": "yarn build",
"test": "jest",
Expand Down Expand Up @@ -50,9 +50,11 @@
"@1stg/husky-config": "^0.1.0",
"@1stg/lint-staged": "^0.1.0",
"@1stg/prettier-config": "^0.1.0",
"@1stg/tsconfig": "^0.1.0",
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-partial-application": "^7.4.4",
"@babel/plugin-proposal-private-methods": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@commitlint/config-conventional": "^8.1.0",
"@types/babel__core": "^7.1.2",
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/class-properties.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`class-properties 1`] = `"Unexpected token ;"`;
3 changes: 3 additions & 0 deletions test/__snapshots__/partial-application.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`partial-application 1`] = `"addOne is not a function"`;
3 changes: 3 additions & 0 deletions test/__snapshots__/private-methods.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`private-methods 1`] = `"Unexpected token ;"`;
11 changes: 11 additions & 0 deletions test/class-properties.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Counter } from './class-properties'
import { execute } from './helpers'

const proposal = 'class-properties'

test(proposal, () => {
expect(() => execute(proposal)).toThrowErrorMatchingSnapshot()
const counter = new Counter()
expect(counter.getCount()).toEqual(0)
expect(counter.increment().getCount()).toEqual(1)
})
12 changes: 12 additions & 0 deletions test/class-properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class Counter {
#x = 0

increment() {
this.#x++
return this
}

getCount() {
return this.#x
}
}
1 change: 0 additions & 1 deletion test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const resolve = (...args: string[]): string => path.resolve(__dirname, ...args)
const read = (file: string): string =>
fs.readFileSync(resolve(file) + '.ts').toString()

// eslint-disable-next-line import/namespace
const transpile = (content: string) => ts.transpile(content)

export const execute = (file: string, ...args: number[] | string[]) =>
Expand Down
9 changes: 9 additions & 0 deletions test/partial-application.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import _ from './partial-application'
import { execute } from './helpers'

const proposal = 'partial-application'

test(proposal, () => {
expect(() => execute(proposal)).toThrowErrorMatchingSnapshot()
expect(_()).toEqual([3, 12])
})
7 changes: 7 additions & 0 deletions test/partial-application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function add(x, y) { return x + y; }

export default () => {
const addOne = add(1, ?);
const addTen = add(?, 10);
return [addOne(2), addTen(2)]
}
11 changes: 11 additions & 0 deletions test/private-methods.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Counter } from './private-methods'
import { execute } from './helpers'

const proposal = 'private-methods'

test(proposal, () => {
expect(() => execute(proposal)).toThrowErrorMatchingSnapshot()
const counter = new Counter()
expect(counter.getCount()).toEqual(0)
expect(counter.increment().getCount()).toEqual(1)
})
16 changes: 16 additions & 0 deletions test/private-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export class Counter {
x = 0

#increment() {
this.x++
return this
}

increment() {
return this.#increment()
}

getCount() {
return this.x
}
}
7 changes: 0 additions & 7 deletions test/tsconfig.json

This file was deleted.

43 changes: 43 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@
"@babel/traverse" "^7.4.4"
"@babel/types" "^7.4.4"

"@babel/helper-create-class-features-plugin@^7.4.4", "@babel/helper-create-class-features-plugin@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.5.5.tgz#401f302c8ddbc0edd36f7c6b2887d8fa1122e5a4"
integrity sha512-ZsxkyYiRA7Bg+ZTRpPvB6AbOFKTFFK4LrvTet8lInm0V468MWCaSYJE+I7v2z2r8KNLtYiV+K5kTCnR7dvyZjg==
dependencies:
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-member-expression-to-functions" "^7.5.5"
"@babel/helper-optimise-call-expression" "^7.0.0"
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/helper-replace-supers" "^7.5.5"
"@babel/helper-split-export-declaration" "^7.4.4"

"@babel/helper-define-map@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.5.5.tgz#3dec32c2046f37e09b28c93eb0b103fd2a25d369"
Expand Down Expand Up @@ -303,6 +315,14 @@
"@babel/helper-remap-async-to-generator" "^7.1.0"
"@babel/plugin-syntax-async-generators" "^7.2.0"

"@babel/plugin-proposal-class-properties@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.5.5.tgz#a974cfae1e37c3110e71f3c6a2e48b8e71958cd4"
integrity sha512-AF79FsnWFxjlaosgdi421vmYG6/jg79bVD0dpD44QdgobzHKuLZ6S3vl8la9qIeSwGi8i1fS0O1mfuDAAdo1/A==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.5.5"
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-proposal-do-expressions@^7.5.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-do-expressions/-/plugin-proposal-do-expressions-7.5.0.tgz#ceb594d4a618545b00aa0b5cd61cad4aaaeb7a5a"
Expand Down Expand Up @@ -384,6 +404,14 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-optional-chaining" "^7.2.0"

"@babel/plugin-proposal-partial-application@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-partial-application/-/plugin-proposal-partial-application-7.4.4.tgz#7e901a687ecc1851b5590052278a3aa840549fa1"
integrity sha512-SnrGdX4pQI9gHE7CSnSQlXThblS9wa1aPf/vROUrTLYtovVlsHRQ+34oXV3uVyYreYVqmIXk+dnS2aPoXUztYg==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-partial-application" "^7.4.4"

"@babel/plugin-proposal-pipeline-operator@^7.5.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-pipeline-operator/-/plugin-proposal-pipeline-operator-7.5.0.tgz#4100ec55ef4f6a4c2490b5f5a4f2a22dfa272c06"
Expand All @@ -392,6 +420,14 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-pipeline-operator" "^7.5.0"

"@babel/plugin-proposal-private-methods@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-methods/-/plugin-proposal-private-methods-7.4.4.tgz#307b7db29d8ae2d259e7c0e6e665b1922d7ac856"
integrity sha512-EIV4fDVP3XwdizJ/H6308Km+d8xdLAUCAvsY8mjxhat9I3vNgssGhZuhgn/jw7IK5/91sN8PHtVGxMjeTSrSng==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.4.4"
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-proposal-throw-expressions@^7.0.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-throw-expressions/-/plugin-proposal-throw-expressions-7.2.0.tgz#2d9e452d370f139000e51db65d0a85dc60c64739"
Expand Down Expand Up @@ -500,6 +536,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-partial-application@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-partial-application/-/plugin-syntax-partial-application-7.4.4.tgz#7dce8a50d16c9dd8de78297db692742f5f9c0b11"
integrity sha512-WXsl5W+Q72AvK71bnbxX1hRxbrEm1rYZcLijReQ0X1Ik6BhXAVR5J/eHxqx155Ib2Ow8+zAunpOUcdi+jKG0Yg==
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-syntax-pipeline-operator@^7.5.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-pipeline-operator/-/plugin-syntax-pipeline-operator-7.5.0.tgz#8ea7c2c22847c797748bf07752722a317079dc1e"
Expand Down

0 comments on commit a7f09da

Please sign in to comment.