Skip to content

Commit 5b7758f

Browse files
committed
fix bugs in jsx crawling that were introduced by using promises for file reads.
1 parent 38eb4e9 commit 5b7758f

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

Diff for: packages/jsx-analyzer/src/importer/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export default function importer(file: JSXTemplate, analysis: Analysis, blockFac
9696

9797
// If this is a jsx or tsx file, parse it with the same analysis object.
9898
if ( fs.existsSync(absoluteFilePath) && VALID_FILE_EXTENSIONS[parsedPath.ext] ) {
99-
parseFileWith(absoluteFilePath, analysis.parent, blockFactory, options);
99+
analysis.parent.analysisPromises.push(parseFileWith(absoluteFilePath, analysis.parent, blockFactory, options));
100100
return;
101101
}
102102

Diff for: packages/jsx-analyzer/src/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,17 @@ export function parse(filename: string, data: string, factory: BlockFactory, opt
145145
let metaAnalysis: MetaAnalysis = new MetaAnalysis();
146146

147147
return Promise.resolve().then(() => {
148-
parseWith(template, metaAnalysis, factory, resolvedOpts);
149-
return Promise.all(metaAnalysis.analysisPromises).then((analyses) => {
150-
analyses.forEach((analysis) => {
151-
traverse(analysis.template.ast, analyzer(analysis));
152-
metaAnalysis.addAnalysis(analysis);
153-
// No need to keep detailed template data anymore!
154-
delete analysis.template.ast;
155-
delete analysis.template.data;
148+
return parseWith(template, metaAnalysis, factory, resolvedOpts).then(analysis => {
149+
return Promise.all(metaAnalysis.analysisPromises).then((analyses) => {
150+
for (let analysis of (new Set(analyses))) {
151+
traverse(analysis.template.ast, analyzer(analysis));
152+
metaAnalysis.addAnalysis(analysis);
153+
// No need to keep detailed template data anymore!
154+
delete analysis.template.ast;
155+
delete analysis.template.data;
156+
}
157+
return metaAnalysis;
156158
});
157-
return metaAnalysis;
158159
});
159160
});
160161
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from 'chai';
2-
import { suite, test, skip } from 'mocha-typescript';
2+
import { suite, test} from 'mocha-typescript';
33
import { MetaAnalysis } from '../../src/utils/Analysis';
44
import { testParseFile as parseFile } from '../util';
55

@@ -8,46 +8,42 @@ const path = require('path');
88
@suite('Dependency Tree Crawling')
99
export class Test {
1010

11-
@skip
1211
@test 'All blocks are discovered in multi-file app from entrypoint'(){
1312
let base = path.resolve(__dirname, '../../../test/fixtures/basic-multifile');
1413
return parseFile('index.tsx', { baseDir: base }).then((analysis: MetaAnalysis) => {
1514
assert.equal(analysis.fileCount(), 2);
1615
assert.equal(analysis.getAnalysis(0).blockCount(), 1);
1716
assert.equal(analysis.getAnalysis(1).blockCount(), 1);
18-
assert.equal(analysis.styleCount(), 4);
17+
assert.equal(analysis.styleCount(), 3);
1918
});
2019
}
2120

22-
@skip
2321
@test 'Duplicate blocks are only parsed once'(){
2422
let base = path.resolve(__dirname, '../../../test/fixtures/duplicate-blocks-multifile');
2523
return parseFile('index.tsx', { baseDir: base }).then((analysis: MetaAnalysis) => {
2624
assert.equal(analysis.fileCount(), 2);
2725
assert.equal(analysis.blockCount(), 1);
2826
assert.equal(analysis.blockPromisesCount(), 1);
29-
assert.equal(analysis.styleCount(), 3);
27+
assert.equal(analysis.styleCount(), 2);
3028
});
3129
}
3230

33-
@skip
3431
@test 'Dependency Tree Crawling finds dependents of dependents'(){
3532
let base = path.resolve(__dirname, '../../../test/fixtures/deep-multifile');
3633
return parseFile('index.tsx', { baseDir: base }).then((analysis: MetaAnalysis) => {
3734
assert.equal(analysis.fileCount(), 3);
3835
assert.equal(analysis.blockCount(), 3);
3936
assert.equal(analysis.blockPromisesCount(), 3);
40-
assert.equal(analysis.styleCount(), 5);
37+
assert.equal(analysis.styleCount(), 4);
4138
});
4239
}
4340

44-
@skip
45-
@test 'Conflicting local import names don\'t interfere with each other'(){
41+
@test "Conflicting local import names don't interfere with each other"(){
4642
let base = path.resolve(__dirname, '../../../test/fixtures/conflicting-local-multifile');
4743
return parseFile('index.tsx', { baseDir: base }).then((analysis: MetaAnalysis) => {
4844
assert.equal(analysis.fileCount(), 2);
4945
assert.equal(analysis.blockCount(), 2);
50-
assert.equal(analysis.styleCount(), 4);
46+
assert.equal(analysis.styleCount(), 3);
5147
});
5248
}
5349
}

0 commit comments

Comments
 (0)