Skip to content

Commit 5bfcbd7

Browse files
committed
use a simpler hashing algorithm when a file system is available
1 parent 2445cca commit 5bfcbd7

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/visitors/displayNameAndId.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ const getFileHash = (state) => {
7676
const moduleName = moduleRoot && JSON.parse(fs.readFileSync(path.join(moduleRoot, 'package.json'))).name
7777
const code = file.code
7878

79-
const fileHash = hash([moduleName, filePath, code].join(''))
79+
const stuffToHash = [moduleName]
80+
81+
if (filePath) {
82+
stuffToHash.push(filePath)
83+
} else {
84+
stuffToHash.push(code)
85+
}
86+
87+
const fileHash = hash(stuffToHash.join(''))
8088
file.set(FILE_HASH, fileHash)
8189
return fileHash
8290
}

test/__snapshots__/index.test.js.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,49 @@ const WrappedComponent = styled(Inner).withConfig({
2424
2525
exports[`fixtures should add identifier 1`] = `
2626
"const Test = styled.div.withConfig({
27-
componentId: \"f15zqz-0\"
27+
componentId: \"iiazu4-0\"
2828
})\`width:100%;\`;
2929
const Test2 = true ? styled.div.withConfig({
30-
componentId: \"f15zqz-1\"
30+
componentId: \"iiazu4-1\"
3131
})\`\` : styled.div.withConfig({
32-
componentId: \"f15zqz-2\"
32+
componentId: \"iiazu4-2\"
3333
})\`\`;
3434
const styles = { One: styled.div.withConfig({
35-
componentId: \"f15zqz-3\"
35+
componentId: \"iiazu4-3\"
3636
})\`\` };
3737
let Component;
3838
Component = styled.div.withConfig({
39-
componentId: \"f15zqz-4\"
39+
componentId: \"iiazu4-4\"
4040
})\`\`;
4141
const WrappedComponent = styled(Inner).withConfig({
42-
componentId: \"f15zqz-5\"
42+
componentId: \"iiazu4-5\"
4343
})\`\`;"
4444
`;
4545
4646
exports[`fixtures should add identifier and display name 1`] = `
4747
"const Test = styled.div.withConfig({
4848
displayName: \"Test\",
49-
componentId: \"s1j54k93-0\"
49+
componentId: \"s1vkcy8r-0\"
5050
})\`width:100%;\`;
5151
const Test2 = true ? styled.div.withConfig({
5252
displayName: \"Test2\",
53-
componentId: \"s1j54k93-1\"
53+
componentId: \"s1vkcy8r-1\"
5454
})\`\` : styled.div.withConfig({
5555
displayName: \"Test2\",
56-
componentId: \"s1j54k93-2\"
56+
componentId: \"s1vkcy8r-2\"
5757
})\`\`;
5858
const styles = { One: styled.div.withConfig({
5959
displayName: \"One\",
60-
componentId: \"s1j54k93-3\"
60+
componentId: \"s1vkcy8r-3\"
6161
})\`\` };
6262
let Component;
6363
Component = styled.div.withConfig({
6464
displayName: \"Component\",
65-
componentId: \"s1j54k93-4\"
65+
componentId: \"s1vkcy8r-4\"
6666
})\`\`;
6767
const WrappedComponent = styled(Inner).withConfig({
6868
displayName: \"WrappedComponent\",
69-
componentId: \"s1j54k93-5\"
69+
componentId: \"s1vkcy8r-5\"
7070
})\`\`;"
7171
`;
7272
@@ -198,27 +198,27 @@ exports[`fixtures should track the imported variable 1`] = `
198198
199199
const Test = s.div.withConfig({
200200
displayName: \"Test\",
201-
componentId: \"syqrfc-0\"
201+
componentId: \"s13i891w-0\"
202202
})\`width:100%;\`;
203203
const Test2 = true ? s.div.withConfig({
204204
displayName: \"Test2\",
205-
componentId: \"syqrfc-1\"
205+
componentId: \"s13i891w-1\"
206206
})\`\` : s.div.withConfig({
207207
displayName: \"Test2\",
208-
componentId: \"syqrfc-2\"
208+
componentId: \"s13i891w-2\"
209209
})\`\`;
210210
const styles = { One: s.div.withConfig({
211211
displayName: \"One\",
212-
componentId: \"syqrfc-3\"
212+
componentId: \"s13i891w-3\"
213213
})\`\` };
214214
let Component;
215215
Component = s.div.withConfig({
216216
displayName: \"Component\",
217-
componentId: \"syqrfc-4\"
217+
componentId: \"s13i891w-4\"
218218
})\`\`;
219219
const WrappedComponent = s(Inner).withConfig({
220220
displayName: \"WrappedComponent\",
221-
componentId: \"syqrfc-5\"
221+
componentId: \"s13i891w-5\"
222222
})\`\`;"
223223
`;
224224
@@ -227,17 +227,17 @@ exports[`fixtures should transpile require default 1`] = `
227227
228228
const TestNormal = styled.div.withConfig({
229229
displayName: \"before__TestNormal\",
230-
componentId: \"y0c69d-0\"
230+
componentId: \"iqyhdm-0\"
231231
})([[\"{width:100%;}\"]]);
232232
233233
const Test = styled_default.default.div.withConfig({
234234
displayName: \"before__Test\",
235-
componentId: \"y0c69d-1\"
235+
componentId: \"iqyhdm-1\"
236236
})([[\"{width:100%;}\"]]);
237237
238238
const TestCallExpression = styled_default.default(Test).withConfig({
239239
displayName: \"before__TestCallExpression\",
240-
componentId: \"y0c69d-2\"
240+
componentId: \"iqyhdm-2\"
241241
})([[\"{height:20px;}\"]]);"
242242
`;
243243
@@ -288,26 +288,26 @@ exports[`fixtures should use file name 1`] = `
288288
289289
const Test = styled.div.withConfig({
290290
displayName: \"before__Test\",
291-
componentId: \"s1x8c0g0-0\"
291+
componentId: \"s1tyeg9p-0\"
292292
})\`color:red;\`;
293293
const before = styled.div.withConfig({
294294
displayName: \"before\",
295-
componentId: \"s1x8c0g0-1\"
295+
componentId: \"s1tyeg9p-1\"
296296
})\`color:blue;\`;
297297
styled.div.withConfig({
298298
displayName: \"before\",
299-
componentId: \"s1x8c0g0-2\"
299+
componentId: \"s1tyeg9p-2\"
300300
})\`\`;
301301
export default styled.button.withConfig({
302302
displayName: \"before\",
303-
componentId: \"s1x8c0g0-3\"
303+
componentId: \"s1tyeg9p-3\"
304304
})\`\`;"
305305
`;
306306
307307
exports[`fixtures should work with hoisted default as import 1`] = `
308308
"const Test = s.div.withConfig({
309309
displayName: \'before__Test\',
310-
componentId: \'s2wuo7o-0\'
310+
componentId: \'s1vk20b3-0\'
311311
})\`width:100%;\`;
312312
import { default as s, css } from \'styled-components\';"
313313
`;

0 commit comments

Comments
 (0)