Skip to content

Commit

Permalink
New: Add sucrase for typescript extensions (gulpjs#66)
Browse files Browse the repository at this point in the history
Co-authored-by: Flip Sasser <flip@inthebackforty.com>
  • Loading branch information
2 people authored and phated committed May 31, 2020
1 parent b8fd457 commit e20d28d
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Map file types to modules which provide a [require.extensions] loader.
'typescript-node/register',
'typescript-register',
'typescript-require',
'sucrase/register/ts',
{
module: '@babel/register',
register: function(hook) {
Expand All @@ -174,6 +175,7 @@ Map file types to modules which provide a [require.extensions] loader.
'.tsx': [
'ts-node/register',
'typescript-node/register',
'sucrase/register',
{
module: '@babel/register',
register: function(hook) {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ var extensions = {
'typescript-node/register',
'typescript-register',
'typescript-require',
'sucrase/register/ts',
{
module: '@babel/register',
register: function(hook) {
Expand All @@ -156,6 +157,7 @@ var extensions = {
'.tsx': [
'ts-node/register',
'typescript-node/register',
'sucrase/register',
{
module: '@babel/register',
register: function(hook) {
Expand Down
6 changes: 1 addition & 5 deletions test/fixtures/ts/4/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0"
"sucrase": "^3.12.1"
}
}
16 changes: 13 additions & 3 deletions test/fixtures/ts/4/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import Component from "./component"
var test = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};

var test = { ...Component }
var main = {
default: test
};

export default test
export = main;
11 changes: 11 additions & 0 deletions test/fixtures/ts/4/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"outDir": ".tmp"
}
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions test/fixtures/ts/5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/ts/5/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Component from "./component"

var test = { ...Component }

export default test
6 changes: 1 addition & 5 deletions test/fixtures/tsx/2/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0"
"sucrase": "^3.12.1"
}
}
8 changes: 3 additions & 5 deletions test/fixtures/tsx/2/test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import data from "./data"

const React = {
createElement(Component: () => any) {
createElement (Component: () => any) {
return Component()
}
}
Expand All @@ -14,7 +12,7 @@ const Component = () => {

// Test harmony object short notation.
return { data: { trueKey, falseKey, subKey } }
}
};

// Test TSX syntax.
export default <Component {...data} />
export default <Component />
12 changes: 12 additions & 0 deletions test/fixtures/tsx/2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"outDir": ".tmp",
"jsx": "react"
}
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions test/fixtures/tsx/3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0"
}
}
20 changes: 20 additions & 0 deletions test/fixtures/tsx/3/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import data from "./data"

const React = {
createElement(Component: () => any) {
return Component()
}
}

// Test harmony arrow functions.
const Component = () => {
var trueKey = true
var falseKey = false
var subKey = { subProp: 1 }

// Test harmony object short notation.
return { data: { trueKey, falseKey, subKey } }
}

// Test TSX syntax.
export default <Component {...data} />
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var minVersions = {
earlgrey: { major: 0, minor: 12 },
esm: { major: 6, minor: 0 },
json5: { major: 6, minor: 0 },
sucrase: { major: 8, minor: 0 },
'ts-node': { major: 4, minor: 0 },
wisp: { major: 0, minor: 12 },
'require-xml': { major: 6, minor: 0 },
Expand Down

0 comments on commit e20d28d

Please sign in to comment.