Skip to content

Commit 144c65c

Browse files
authored
Merge pull request #377 from smphhh/const-enum-re-export
Add test for handling re-exported const enums (issue #376)
2 parents 85186f4 + b2528ed commit 144c65c

File tree

36 files changed

+638
-36
lines changed

36 files changed

+638
-36
lines changed

src/after-compile.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function determineFilesToCheckForErrors(
100100
} else if (modifiedFiles) {
101101
// check all modified files, and all dependants
102102
Object.keys(modifiedFiles).forEach(modifiedFileName => {
103-
collectAllDependants(instance.reverseDependencyGraph, modifiedFileName)
103+
utils.collectAllDependants(instance.reverseDependencyGraph, modifiedFileName)
104104
.forEach(fileName => {
105105
filesToCheckForErrors[fileName] = files[fileName];
106106
});
@@ -193,26 +193,4 @@ function removeTSLoaderErrors(errors: interfaces.WebpackError[]) {
193193
}
194194
}
195195

196-
/**
197-
* Recursively collect all possible dependants of passed file
198-
*/
199-
function collectAllDependants(
200-
reverseDependencyGraph: interfaces.ReverseDependencyGraph,
201-
fileName: string,
202-
collected: {[file:string]: boolean} = {}
203-
): string[] {
204-
const result = {};
205-
result[fileName] = true;
206-
collected[fileName] = true;
207-
if (reverseDependencyGraph[fileName]) {
208-
Object.keys(reverseDependencyGraph[fileName]).forEach(dependantFileName => {
209-
if (!collected[dependantFileName]) {
210-
collectAllDependants(reverseDependencyGraph, dependantFileName, collected)
211-
.forEach(fName => result[fName] = true);
212-
}
213-
});
214-
}
215-
return Object.keys(result);
216-
}
217-
218196
export = makeAfterCompile;

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ function getEmit(
110110
const allDefinitionFiles = Object.keys(instance.files).filter(fp => definitionFileRegex.test(fp));
111111
allDefinitionFiles.forEach(loader.addDependency.bind(loader));
112112

113-
// Additionally make this file dependent on all imported files
114-
let additionalDependencies = instance.dependencyGraph[filePath];
113+
// Additionally make this file dependent on all imported files as well
114+
// as any deeper recursive dependencies
115+
let additionalDependencies = utils.collectAllDependencies(instance.dependencyGraph, filePath);
115116
if (additionalDependencies) {
116117
additionalDependencies.forEach(loader.addDependency.bind(loader));
117118
}

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export interface TSInstances {
133133
[name: string]: TSInstance;
134134
}
135135

136-
interface DependencyGraph {
136+
export interface DependencyGraph {
137137
[file: string]: string[];
138138
}
139139

src/utils.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,48 @@ export function appendTsSuffixIfMatch(patterns: RegExp[], path: string): string
8686
}
8787
return path;
8888
}
89+
90+
/**
91+
* Recursively collect all possible dependants of passed file
92+
*/
93+
export function collectAllDependants(
94+
reverseDependencyGraph: interfaces.ReverseDependencyGraph,
95+
fileName: string,
96+
collected: {[file:string]: boolean} = {}
97+
): string[] {
98+
const result = {};
99+
result[fileName] = true;
100+
collected[fileName] = true;
101+
if (reverseDependencyGraph[fileName]) {
102+
Object.keys(reverseDependencyGraph[fileName]).forEach(dependantFileName => {
103+
if (!collected[dependantFileName]) {
104+
collectAllDependants(reverseDependencyGraph, dependantFileName, collected)
105+
.forEach(fName => result[fName] = true);
106+
}
107+
});
108+
}
109+
return Object.keys(result);
110+
}
111+
112+
/**
113+
* Recursively collect all possible dependencies of passed file
114+
*/
115+
export function collectAllDependencies(
116+
dependencyGraph: interfaces.DependencyGraph,
117+
filePath: string,
118+
collected: {[file:string]: boolean} = {}
119+
): string[] {
120+
const result = {};
121+
result[filePath] = true;
122+
collected[filePath] = true;
123+
let directDependencies = dependencyGraph[filePath];
124+
if (directDependencies) {
125+
directDependencies.forEach(dependencyFilePath => {
126+
if (!collected[dependencyFilePath]) {
127+
collectAllDependencies(dependencyGraph, dependencyFilePath, collected)
128+
.forEach(fPath => result[fPath] = true);
129+
}
130+
});
131+
}
132+
return Object.keys(result);
133+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { BarEnum } from './foo';
2+
3+
console.log(BarEnum.Bar);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const enum BarEnum {
2+
Bar = 1
3+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId])
10+
/******/ return installedModules[moduleId].exports;
11+
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ exports: {},
15+
/******/ id: moduleId,
16+
/******/ loaded: false
17+
/******/ };
18+
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
22+
/******/ // Flag the module as loaded
23+
/******/ module.loaded = true;
24+
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
29+
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
36+
/******/ // __webpack_public_path__
37+
/******/ __webpack_require__.p = "";
38+
39+
/******/ // Load entry module and return exports
40+
/******/ return __webpack_require__(0);
41+
/******/ })
42+
/************************************************************************/
43+
/******/ ([
44+
/* 0 */
45+
/***/ function(module, exports) {
46+
47+
"use strict";
48+
console.log(1 /* Bar */);
49+
50+
51+
/***/ }
52+
/******/ ]);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId])
10+
/******/ return installedModules[moduleId].exports;
11+
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ exports: {},
15+
/******/ id: moduleId,
16+
/******/ loaded: false
17+
/******/ };
18+
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
22+
/******/ // Flag the module as loaded
23+
/******/ module.loaded = true;
24+
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
29+
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
36+
/******/ // __webpack_public_path__
37+
/******/ __webpack_require__.p = "";
38+
39+
/******/ // Load entry module and return exports
40+
/******/ return __webpack_require__(0);
41+
/******/ })
42+
/************************************************************************/
43+
/******/ ([
44+
/* 0 */
45+
/***/ function(module, exports, __webpack_require__) {
46+
47+
"use strict";
48+
var foo_1 = __webpack_require__(1);
49+
console.log(foo_1.BarEnum.Bar);
50+
51+
52+
/***/ },
53+
/* 1 */
54+
/***/ function(module, exports, __webpack_require__) {
55+
56+
"use strict";
57+
var bar_1 = __webpack_require__(2);
58+
exports.BarEnum = bar_1.BarEnum;
59+
60+
61+
/***/ },
62+
/* 2 */
63+
/***/ function(module, exports) {
64+
65+
"use strict";
66+
(function (BarEnum) {
67+
BarEnum[BarEnum["Bar"] = 1] = "Bar";
68+
})(exports.BarEnum || (exports.BarEnum = {}));
69+
var BarEnum = exports.BarEnum;
70+
;
71+
72+
73+
/***/ }
74+
/******/ ]);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Asset Size Chunks Chunk Names
2+
bundle.js 1.87 kB 0 [emitted] main
3+
chunk {0} bundle.js (main) 310 bytes [rendered]
4+
[0] ./.test/constEnumReExportWatch/app.ts 76 bytes {0} [built]
5+
[1] ./.test/constEnumReExportWatch/foo.ts 77 bytes {0} [built]
6+
[2] ./.test/constEnumReExportWatch/bar.ts 157 bytes {0} [built]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Asset Size Chunks Chunk Names
2+
bundle.js 1.43 kB 0 [emitted] main
3+
chunk {0} bundle.js (main) 40 bytes [rendered]
4+
[0] ./.test/constEnumReExportWatch/app.ts 40 bytes {0} [built]

0 commit comments

Comments
 (0)