Skip to content

Commit d9e163f

Browse files
committed
publish and export anymone
1 parent 1f6cabd commit d9e163f

File tree

8 files changed

+111
-18
lines changed

8 files changed

+111
-18
lines changed

lib/react-hot.dev.js

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-hot.dev.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-react-hot-transformer",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"descripton": "react hot transformer for ts,and no babel",
55
"main": "index.js",
66
"typings": "index.d.ts",

src/react-hot.dev.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,31 @@ export default function transformer() {
156156
})
157157
);
158158
if (ts.isClassDeclaration(node) && node.decorators) {
159+
const name = node.name
160+
? ts.createIdentifier(node.name.getText())
161+
: ts.createIdentifier(ID);
159162
return [
160163
ts.updateClassDeclaration(
161164
node,
162165
node.decorators,
163166
undefined,
164-
node.name,
167+
name,
165168
node.typeParameters,
166169
node.heritageClauses,
167170
node.members
168171
),
169-
ts.createVariableDeclarationList(
170-
[
171-
ts.createVariableDeclaration(
172-
ID,
173-
undefined,
174-
ts.createIdentifier(node.name.getText())
175-
),
176-
],
177-
ts.NodeFlags.Const
178-
),
172+
node.name
173+
? ts.createVariableDeclarationList(
174+
[
175+
ts.createVariableDeclaration(
176+
ID,
177+
undefined,
178+
ts.createIdentifier(node.name.getText())
179+
),
180+
],
181+
ts.NodeFlags.Const
182+
)
183+
: ts.createEmptyStatement(),
179184
ts.createExportAssignment(undefined, undefined, false, ts.createIdentifier(ID)),
180185
];
181186
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const a = new class {
2+
fun() { }
3+
}()
4+
export default class {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const a = new class {
2+
fun() { }
3+
}()
4+
@ccccc
5+
export default class {}

test/__snapshots__/react-hot.components.test.ts.snap

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,80 @@ leaveModule(module);
6565
}());
6666
6767
68+
;
69+
"
70+
`;
71+
72+
exports[`React components classAnonymous.js 1`] = `
73+
"(function () {
74+
var enterModule = require('react-hot-loader').enterModule;
75+
enterModule && enterModule(module);
76+
}());
77+
78+
79+
;
80+
const a = new class {
81+
fun() { }
82+
}();
83+
const _default = class {
84+
}
85+
export default _default;
86+
87+
88+
;
89+
(function () {
90+
var reactHotLoader = require('react-hot-loader').default;
91+
var leaveModule = require('react-hot-loader').leaveModule;
92+
93+
if (!reactHotLoader) {
94+
return;
95+
}
96+
97+
reactHotLoader.register(a, \\"a\\", \\"classAnonymous.js\\");
98+
reactHotLoader.register(_default, \\"default\\", \\"classAnonymous.js\\");
99+
100+
leaveModule(module);
101+
}());
102+
103+
104+
;
105+
"
106+
`;
107+
108+
exports[`React components classAnonymousDecorator.js 1`] = `
109+
"(function () {
110+
var enterModule = require('react-hot-loader').enterModule;
111+
enterModule && enterModule(module);
112+
}());
113+
114+
115+
;
116+
const a = new class {
117+
fun() { }
118+
}();
119+
@ccccc
120+
class _default {
121+
}
122+
;
123+
export default _default;
124+
125+
126+
;
127+
(function () {
128+
var reactHotLoader = require('react-hot-loader').default;
129+
var leaveModule = require('react-hot-loader').leaveModule;
130+
131+
if (!reactHotLoader) {
132+
return;
133+
}
134+
135+
reactHotLoader.register(a, \\"a\\", \\"classAnonymousDecorator.js\\");
136+
reactHotLoader.register(_default, \\"default\\", \\"classAnonymousDecorator.js\\");
137+
138+
leaveModule(module);
139+
}());
140+
141+
68142
;
69143
"
70144
`;

test/react-hot.components.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function addRHLPlugin(prod = false) {
1212
describe('React components', () => {
1313
readdirSync(FIXTURES_DIR).forEach(fixtureName => {
1414
const fixtureFile = join(FIXTURES_DIR, fixtureName);
15-
// const testFile: Array<string> = ['test.js'];
15+
// const testFile: Array<string> = ['classAnonymousDecorator.js','classAnonymous.js'];
1616
// if (statSync(fixtureFile).isFile() && testFile.indexOf(fixtureName) > -1) {
1717
if (statSync(fixtureFile).isFile()) {
1818
it(fixtureName.split('-').join(' '), () => {

0 commit comments

Comments
 (0)