Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit ac34cfd

Browse files
committed
Use babel to transpile.
1 parent 637d7c8 commit ac34cfd

File tree

10 files changed

+61
-17
lines changed

10 files changed

+61
-17
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"syntax-dynamic-import",
1818
["transform-class-properties", { "spec": true }],
1919
["transform-object-rest-spread", {"useBuiltIns": true}],
20-
"lodash"
20+
"lodash",
21+
"react-hot-loader/babel"
2122
]
2223
}

app/assets/javascripts/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'core-js/shim'
1+
import 'babel-polyfill'
22
import 'javascripts/change-query'
33
import * as Rails from 'rails-ujs'
44

app/assets/javascripts/change-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function prepereSelectElems(): void {
66
) as NodeListOf<HTMLSelectElement>
77
const query = queryString.parse(location.search)
88

9-
for (const select of Array.from(doms)) {
9+
for (const select of doms) {
1010
if (query.sort_by) {
1111
select.value = query.sort_by
1212
}
@@ -23,7 +23,7 @@ function prepereCheckboxElems(): void {
2323
) as NodeListOf<HTMLInputElement>
2424
const query = queryString.parse(location.search)
2525

26-
for (const checkbox of Array.from(doms)) {
26+
for (const checkbox of doms) {
2727
checkbox.checked = query.done && query.done !== 'false'
2828
checkbox.addEventListener('change', () => {
2929
query.done = checkbox.checked

app/assets/javascripts/todos/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/assets/javascripts/todos/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Todo {
1010
export class IdentifiableError extends Error {
1111
constructor(readonly targetId: number, message?: string) {
1212
super(message)
13-
Object.setPrototypeOf(this, new.target.prototype)
13+
Object.setPrototypeOf(this, this.constructor.prototype) // restore prototype chain
1414
this.name = 'IdentifiableError'
1515
}
1616
}

config/espower-typescript.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
var ts = require('typescript');
5+
6+
var pattern = 'test/**/*.@(ts|tsx)';
7+
var cwd = process.cwd();
8+
var packageData = require(path.join(cwd, 'package.json'));
9+
10+
if (packageData &&
11+
typeof packageData.directories === 'object' &&
12+
typeof packageData.directories.test === 'string') {
13+
var testDir = packageData.directories.test;
14+
pattern = testDir + ((testDir.lastIndexOf('/', 0) === 0) ? '' : '/') + '**/*.@(ts|tsx)';
15+
}
16+
17+
var tsconfigPath = ts.findConfigFile(cwd, fs.existsSync, 'tsconfig.test.json');
18+
var tsconfigBasepath = null;
19+
var compilerOptions = null;
20+
if (tsconfigPath) {
21+
compilerOptions = parseTsConfig(tsconfigPath);
22+
tsconfigBasepath = path.dirname(tsconfigPath);
23+
}
24+
25+
require('espower-typescript')({
26+
cwd: cwd,
27+
pattern: pattern,
28+
compilerOptions: compilerOptions,
29+
basepath: tsconfigBasepath
30+
});
31+
32+
function parseTsConfig(tsconfigPath) {
33+
var parsed = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, 'utf8'));
34+
if (parsed.error) {
35+
throw new Error(parsed.error.messageText);
36+
}
37+
38+
if (!parsed.config || !parsed.config.compilerOptions) {
39+
return null;
40+
}
41+
42+
return parsed.config.compilerOptions;
43+
}

config/webpack/environment.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ function enableCssModules(cssLoader) {
2121
environment.loaders.set('typescript', {
2222
test: /\.tsx?$/,
2323
exclude: /node_modules/,
24-
loader: [
25-
'react-hot-loader/webpack',
26-
'awesome-typescript-loader'
27-
]
24+
loader: 'awesome-typescript-loader'
2825
})
2926

3027
// Limit this loader to specific paths

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"lint": "tslint -c tslint.json 'app/**/*.ts' 'app/**/*.tsx'",
66
"lint:fix": "tslint -c tslint.json 'app/**/*.ts' '**/*.tsx' --fix",
7-
"test": "mocha --require espower-typescript/guess **/*.spec.{ts,tsx}",
7+
"test": "mocha --require ./config/espower-typescript.js **/*.spec.{ts,tsx}",
88
"storybook": "start-storybook -p 6006",
99
"prettier": "prettier --single-quote --trailing-comma=es5 --no-semi --write '**/*.ts' --write '**/*.tsx'",
1010
"precommit-check": "npm run prettier && npm run lint && npm run test"
@@ -25,11 +25,11 @@
2525
"autoprefixer": "^7.1.1",
2626
"awesome-typescript-loader": "^3.2.3",
2727
"babel-plugin-lodash": "^3.2.11",
28+
"babel-polyfill": "^6.26.0",
2829
"babel-preset-react": "^6.24.1",
2930
"bootstrap": "^3.3.7",
3031
"classnames": "^2.2.5",
3132
"coffeescript": "^2.0.1",
32-
"core-js": "^2.5.1",
3333
"lodash": "^4.17.4",
3434
"moment": "^2.18.1",
3535
"query-string": "^4.3.4",

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"sourceMap": true,
44
"noImplicitAny": true,
55
"strictNullChecks": true,
6-
"target": "es5",
6+
"target": "esnext",
77
"moduleResolution": "node",
8-
"jsx": "react",
9-
"lib": ["dom", "es6"]
8+
"jsx": "preserve"
109
},
1110
"include": [
1211
"./app/assets/javascripts/**/*",
1312
"./app/assets/packs/**/*"
1413
],
1514
"awesomeTypescriptLoaderOptions": {
15+
"useBabel": true,
1616
"useCache": true
1717
}
1818
}

tsconfig.test.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"jsx": "react"
5+
}
6+
}

0 commit comments

Comments
 (0)