Skip to content

Commit 887bdbc

Browse files
author
Robert Jackson
authored
[BUGFIX] if our ancestor import declaration is removed short-circuit … (#79)
[BUGFIX] if our ancestor import declaration is removed short-circuit …
2 parents 65031d1 + 3358c58 commit 887bdbc

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@babel/preset-env": "^7.0.0",
3939
"babel-core": "^6.26.0",
4040
"babel-preset-env": "^1.6.1",
41+
"chai": "^4.2.0",
4142
"eslint": "^4.19.1",
4243
"eslint-config-prettier": "^2.9.0",
4344
"eslint-plugin-node": "^6.0.1",

src/utils/macros.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = class Macros {
1313
this.builder = new Builder(babel.types, {
1414
module: this.debugHelpers.module,
1515
global: this.debugHelpers.global,
16-
assertPredicateIndex: options.debugTools.assertPredicateIndex,
16+
assertPredicateIndex: options.debugTools && options.debugTools.assertPredicateIndex,
1717
isDebug: options.debugTools.isDebug,
1818
});
1919
}
@@ -58,6 +58,10 @@ module.exports = class Macros {
5858
if (!this.debugHelpers.module) {
5959
if (this.localDebugBindings.length > 0) {
6060
let importPath = this.localDebugBindings[0].findParent(p => p.isImportDeclaration());
61+
if (importPath === null) {
62+
// import declaration in question seems to have already been removed
63+
return;
64+
}
6165
let specifiers = importPath.get('specifiers');
6266

6367
if (specifiers.length === this.localDebugBindings.length) {

tests/utils-macros-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const macros = require('../src/index.js');
4+
const { transformSync } = require('@babel/core');
5+
const { expect } = require('chai');
6+
7+
describe('utils/macros.js', function() {
8+
it('does not fail if an import intended to be removed has already been removed', function() {
9+
const { code } = transformSync(`import { warn } from '@ember/debug-tools'`, {
10+
plugins: [
11+
{
12+
name: 'other plugin that removes stuff',
13+
visitor: {
14+
Program: {
15+
exit(path) {
16+
path.get('body').forEach(item => {
17+
if (item.isImportDeclaration()) {
18+
item.remove();
19+
}
20+
});
21+
},
22+
},
23+
},
24+
},
25+
[
26+
macros,
27+
{
28+
debugTools: {
29+
isDebug: true,
30+
source: '@ember/debug-tools',
31+
},
32+
},
33+
],
34+
],
35+
filename: 'some-file.js',
36+
});
37+
38+
expect(code).to.eql('');
39+
});
40+
});

yarn.lock

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,11 @@ [email protected], assert-plus@^1.0.0:
787787
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
788788
integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=
789789

790+
assertion-error@^1.1.0:
791+
version "1.1.0"
792+
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
793+
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==
794+
790795
assign-symbols@^1.0.0:
791796
version "1.0.0"
792797
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
@@ -1549,6 +1554,18 @@ caseless@~0.12.0:
15491554
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
15501555
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
15511556

1557+
chai@^4.2.0:
1558+
version "4.2.0"
1559+
resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5"
1560+
integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==
1561+
dependencies:
1562+
assertion-error "^1.1.0"
1563+
check-error "^1.0.2"
1564+
deep-eql "^3.0.1"
1565+
get-func-name "^2.0.0"
1566+
pathval "^1.1.0"
1567+
type-detect "^4.0.5"
1568+
15521569
chalk@^1.1.3:
15531570
version "1.1.3"
15541571
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -1583,6 +1600,11 @@ chardet@^0.4.0:
15831600
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
15841601
integrity sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=
15851602

1603+
check-error@^1.0.2:
1604+
version "1.0.2"
1605+
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
1606+
integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=
1607+
15861608
chownr@^1.1.1:
15871609
version "1.1.1"
15881610
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494"
@@ -1837,6 +1859,13 @@ decode-uri-component@^0.2.0:
18371859
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
18381860
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
18391861

1862+
deep-eql@^3.0.1:
1863+
version "3.0.1"
1864+
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
1865+
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
1866+
dependencies:
1867+
type-detect "^4.0.0"
1868+
18401869
deep-extend@^0.6.0:
18411870
version "0.6.0"
18421871
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
@@ -2498,6 +2527,11 @@ get-caller-file@^1.0.1:
24982527
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
24992528
integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==
25002529

2530+
get-func-name@^2.0.0:
2531+
version "2.0.0"
2532+
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
2533+
integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=
2534+
25012535
get-stdin@^5.0.1:
25022536
version "5.0.1"
25032537
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"
@@ -4210,6 +4244,11 @@ path-type@^2.0.0:
42104244
dependencies:
42114245
pify "^2.0.0"
42124246

4247+
pathval@^1.1.0:
4248+
version "1.1.0"
4249+
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
4250+
integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA=
4251+
42134252
performance-now@^2.1.0:
42144253
version "2.1.0"
42154254
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -5201,6 +5240,11 @@ type-check@~0.3.2:
52015240
dependencies:
52025241
prelude-ls "~1.1.2"
52035242

5243+
type-detect@^4.0.0, type-detect@^4.0.5:
5244+
version "4.0.8"
5245+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
5246+
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
5247+
52045248
typedarray@^0.0.6:
52055249
version "0.0.6"
52065250
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

0 commit comments

Comments
 (0)