Skip to content

Commit

Permalink
test(es/transforms/cjs): update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Oct 31, 2021
1 parent 0a963e8 commit 03edc8a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 115 deletions.
73 changes: 34 additions & 39 deletions ecmascript/transforms/module/tests/common_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,11 +1251,9 @@ var _exportNames = {
};
var _white = require("white");
var _black = require("black");
Object.keys(_white).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _white[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
Expand All @@ -1265,6 +1263,8 @@ Object.keys(_white).forEach(function (key) {
});
});
var _black = require("black");
Object.keys(_black).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Expand Down Expand Up @@ -3785,21 +3785,12 @@ export * from 'react';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
// The fact that this exports both a normal default, and all of the names via
// re-export is an edge case that is important not to miss. See
// https://github.com/babel/babel/issues/8306 as an example.
var _default = _react.default;
exports.default = _default;
Object.keys(_react).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _react[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
Expand All @@ -3809,6 +3800,12 @@ Object.keys(_react).forEach(function (key) {
});
});
// The fact that this exports both a normal default, and all of the names via
// re-export is an edge case that is important not to miss. See
// https://github.com/babel/babel/issues/8306 as an example.
var _default = _react.default;
exports.default = _default;
"#
);

Expand Down Expand Up @@ -4093,19 +4090,19 @@ test!(
issue_962,
"import root from './_root.js';
import stubFalse from './stubFalse.js';
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && \
module;
var moduleExports = freeModule && freeModule.exports === freeExports;
var Buffer = moduleExports ? root.Buffer : undefined;
var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
var isBuffer = nativeIsBuffer || stubFalse;
export default isBuffer",
r#"
"use strict";
Expand Down Expand Up @@ -4167,7 +4164,6 @@ Object.defineProperty(exports, "Scope", {
}
});
var _http = require("./http");
var _interfaces = require("./interfaces");
Object.keys(_http).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _http[key]) return;
Expand All @@ -4178,6 +4174,7 @@ Object.keys(_http).forEach(function(key) {
}
});
});
var _interfaces = require("./interfaces");
"#
);

Expand Down Expand Up @@ -4209,11 +4206,8 @@ export * from './pipes';
};
require("reflect-metadata");
var _http = require("./http");
var _interfaces = require("./interfaces");
var _pipes = require("./pipes");
Object.keys(_http).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _http[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
Expand All @@ -4222,6 +4216,8 @@ export * from './pipes';
}
});
});
var _interfaces = require("./interfaces");
var _pipes = require("./pipes");
Object.keys(_pipes).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Expand Down Expand Up @@ -4539,7 +4535,7 @@ test!(
console.log(foo);
}
}
export default class NotOK {
constructor() {
console.log(foo);
Expand All @@ -4552,9 +4548,9 @@ test!(
value: true
});
exports.default = void 0;
var _foo = _interopRequireDefault(require('foo'));
class OK {
constructor() {
console.log(_foo.default);
Expand Down Expand Up @@ -4680,11 +4676,11 @@ test!(
});
exports.get = get;
exports.default = void 0;
function get(key) {
console.log(key);
}
var _default = a;
exports.default = _default;
"
Expand Down Expand Up @@ -4751,20 +4747,17 @@ test!(
};
exports.BIZ = void 0;
var _file1 = require('./File1');
var _file2 = require('./File2');
const BIZ = 'biz';
exports.BIZ = BIZ;
Object.keys(_file1).forEach(function(key) {
if (key === 'default' || key === '__esModule') return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _file1[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _file1[key];
}
});
if (key === 'default' || key === '__esModule') return;
if (key in exports && exports[key] === _file1[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _file1[key];
}
});
});
var _file2 = require('./File2');
Object.keys(_file2).forEach(function(key) {
if (key === 'default' || key === '__esModule') return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Expand All @@ -4776,6 +4769,8 @@ test!(
}
});
});
const BIZ = 'biz';
exports.BIZ = BIZ;
"
);

Expand Down Expand Up @@ -4917,7 +4912,7 @@ test!(
ignore_dynamic_1,
"
import foo from 'foo';
function foo() {
await import('foo');
Expand Down
20 changes: 10 additions & 10 deletions tests/fixture/issue-1714/case1/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Object.defineProperty(exports, "render", {
});
var _customRender = require("./customRender");
var _react = _interopRequireWildcard(require("@testing-library/react"));
Object.keys(_react).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _react[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _react[key];
}
});
});
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
Expand All @@ -33,13 +43,3 @@ function _interopRequireWildcard(obj) {
return newObj;
}
}
Object.keys(_react).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _react[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _react[key];
}
});
});
43 changes: 21 additions & 22 deletions tests/fixture/issue-1859/case1-js/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ Object.defineProperty(exports, "__esModule", {
var _exportNames = {
};
var _appConfig = _interopRequireWildcard(require("./app.config"));
Object.keys(_appConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _appConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _appConfig[key];
}
});
});
var _databaseConfig = _interopRequireWildcard(require("./database.config"));
Object.keys(_databaseConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _databaseConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _databaseConfig[key];
}
});
});
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
Expand All @@ -29,25 +50,3 @@ function _interopRequireWildcard(obj) {
return newObj;
}
}
Object.keys(_appConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _appConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _appConfig[key];
}
});
});
Object.keys(_databaseConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _databaseConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _databaseConfig[key];
}
});
});
43 changes: 21 additions & 22 deletions tests/fixture/issue-1859/case2-ts/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ Object.defineProperty(exports, "__esModule", {
var _exportNames = {
};
var _appConfig = _interopRequireWildcard(require("./app.config"));
Object.keys(_appConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _appConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _appConfig[key];
}
});
});
var _databaseConfig = _interopRequireWildcard(require("./database.config"));
Object.keys(_databaseConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _databaseConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _databaseConfig[key];
}
});
});
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
Expand All @@ -29,25 +50,3 @@ function _interopRequireWildcard(obj) {
return newObj;
}
}
Object.keys(_appConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _appConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _appConfig[key];
}
});
});
Object.keys(_databaseConfig).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _databaseConfig[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _databaseConfig[key];
}
});
});
43 changes: 21 additions & 22 deletions tests/fixture/issue-1859/case3/output/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ Object.defineProperty(exports, "__esModule", {
var _exportNames = {
};
var _foo = _interopRequireWildcard(require("./foo"));
Object.keys(_foo).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _foo[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _foo[key];
}
});
});
var _bar = _interopRequireWildcard(require("./bar"));
Object.keys(_bar).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _bar[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _bar[key];
}
});
});
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
Expand All @@ -29,25 +50,3 @@ function _interopRequireWildcard(obj) {
return newObj;
}
}
Object.keys(_foo).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _foo[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _foo[key];
}
});
});
Object.keys(_bar).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _bar[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _bar[key];
}
});
});

0 comments on commit 03edc8a

Please sign in to comment.