Skip to content

Commit

Permalink
Merge pull request #377 from smphhh/const-enum-re-export
Browse files Browse the repository at this point in the history
Add test for handling re-exported const enums (issue #376)
  • Loading branch information
johnnyreilly authored Nov 18, 2016
2 parents 85186f4 + b2528ed commit 144c65c
Show file tree
Hide file tree
Showing 36 changed files with 638 additions and 36 deletions.
24 changes: 1 addition & 23 deletions src/after-compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function determineFilesToCheckForErrors(
} else if (modifiedFiles) {
// check all modified files, and all dependants
Object.keys(modifiedFiles).forEach(modifiedFileName => {
collectAllDependants(instance.reverseDependencyGraph, modifiedFileName)
utils.collectAllDependants(instance.reverseDependencyGraph, modifiedFileName)
.forEach(fileName => {
filesToCheckForErrors[fileName] = files[fileName];
});
Expand Down Expand Up @@ -193,26 +193,4 @@ function removeTSLoaderErrors(errors: interfaces.WebpackError[]) {
}
}

/**
* Recursively collect all possible dependants of passed file
*/
function collectAllDependants(
reverseDependencyGraph: interfaces.ReverseDependencyGraph,
fileName: string,
collected: {[file:string]: boolean} = {}
): string[] {
const result = {};
result[fileName] = true;
collected[fileName] = true;
if (reverseDependencyGraph[fileName]) {
Object.keys(reverseDependencyGraph[fileName]).forEach(dependantFileName => {
if (!collected[dependantFileName]) {
collectAllDependants(reverseDependencyGraph, dependantFileName, collected)
.forEach(fName => result[fName] = true);
}
});
}
return Object.keys(result);
}

export = makeAfterCompile;
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ function getEmit(
const allDefinitionFiles = Object.keys(instance.files).filter(fp => definitionFileRegex.test(fp));
allDefinitionFiles.forEach(loader.addDependency.bind(loader));

// Additionally make this file dependent on all imported files
let additionalDependencies = instance.dependencyGraph[filePath];
// Additionally make this file dependent on all imported files as well
// as any deeper recursive dependencies
let additionalDependencies = utils.collectAllDependencies(instance.dependencyGraph, filePath);
if (additionalDependencies) {
additionalDependencies.forEach(loader.addDependency.bind(loader));
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export interface TSInstances {
[name: string]: TSInstance;
}

interface DependencyGraph {
export interface DependencyGraph {
[file: string]: string[];
}

Expand Down
45 changes: 45 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,48 @@ export function appendTsSuffixIfMatch(patterns: RegExp[], path: string): string
}
return path;
}

/**
* Recursively collect all possible dependants of passed file
*/
export function collectAllDependants(
reverseDependencyGraph: interfaces.ReverseDependencyGraph,
fileName: string,
collected: {[file:string]: boolean} = {}
): string[] {
const result = {};
result[fileName] = true;
collected[fileName] = true;
if (reverseDependencyGraph[fileName]) {
Object.keys(reverseDependencyGraph[fileName]).forEach(dependantFileName => {
if (!collected[dependantFileName]) {
collectAllDependants(reverseDependencyGraph, dependantFileName, collected)
.forEach(fName => result[fName] = true);
}
});
}
return Object.keys(result);
}

/**
* Recursively collect all possible dependencies of passed file
*/
export function collectAllDependencies(
dependencyGraph: interfaces.DependencyGraph,
filePath: string,
collected: {[file:string]: boolean} = {}
): string[] {
const result = {};
result[filePath] = true;
collected[filePath] = true;
let directDependencies = dependencyGraph[filePath];
if (directDependencies) {
directDependencies.forEach(dependencyFilePath => {
if (!collected[dependencyFilePath]) {
collectAllDependencies(dependencyGraph, dependencyFilePath, collected)
.forEach(fPath => result[fPath] = true);
}
});
}
return Object.keys(result);
}
3 changes: 3 additions & 0 deletions test/comparison-tests/constEnumReExportWatch/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BarEnum } from './foo';

console.log(BarEnum.Bar);
3 changes: 3 additions & 0 deletions test/comparison-tests/constEnumReExportWatch/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const enum BarEnum {
Bar = 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

"use strict";
console.log(1 /* Bar */);


/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
var foo_1 = __webpack_require__(1);
console.log(foo_1.BarEnum.Bar);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
var bar_1 = __webpack_require__(2);
exports.BarEnum = bar_1.BarEnum;


/***/ },
/* 2 */
/***/ function(module, exports) {

"use strict";
(function (BarEnum) {
BarEnum[BarEnum["Bar"] = 1] = "Bar";
})(exports.BarEnum || (exports.BarEnum = {}));
var BarEnum = exports.BarEnum;
;


/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.87 kB 0 [emitted] main
chunk {0} bundle.js (main) 310 bytes [rendered]
[0] ./.test/constEnumReExportWatch/app.ts 76 bytes {0} [built]
[1] ./.test/constEnumReExportWatch/foo.ts 77 bytes {0} [built]
[2] ./.test/constEnumReExportWatch/bar.ts 157 bytes {0} [built]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.43 kB 0 [emitted] main
chunk {0} bundle.js (main) 40 bytes [rendered]
[0] ./.test/constEnumReExportWatch/app.ts 40 bytes {0} [built]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

"use strict";
console.log(2 /* Bar */);


/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
var foo_1 = __webpack_require__(1);
console.log(foo_1.BarEnum.Bar);


/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {

"use strict";
var bar_1 = __webpack_require__(2);
exports.BarEnum = bar_1.BarEnum;


/***/ },
/* 2 */
/***/ function(module, exports) {

"use strict";
(function (BarEnum) {
BarEnum[BarEnum["Bar"] = 2] = "Bar";
})(exports.BarEnum || (exports.BarEnum = {}));
var BarEnum = exports.BarEnum;
;


/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Asset Size Chunks Chunk Names
bundle.js 1.87 kB 0 [emitted] main
chunk {0} bundle.js (main) 310 bytes [rendered]
[0] ./.test/constEnumReExportWatch/app.ts 76 bytes {0}
[1] ./.test/constEnumReExportWatch/foo.ts 77 bytes {0}
[2] ./.test/constEnumReExportWatch/bar.ts 157 bytes {0} [built]
Loading

0 comments on commit 144c65c

Please sign in to comment.