Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly handle side effects when a namespace is nested in an object (…
- Loading branch information
1 parent
554ba9f
commit 5613b96
Showing
22 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
test/function/samples/namespace-member-side-effects/assignment/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
description: 'checks side effects when reassigning namespace members', | ||
options: { | ||
treeshake: { tryCatchDeoptimization: false } | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/assignment/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as namespace from './namespace.js'; | ||
|
||
export default { | ||
namespace | ||
}; |
Empty file.
9 changes: 9 additions & 0 deletions
9
test/function/samples/namespace-member-side-effects/assignment/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import api from './api/index'; | ||
|
||
let errored = false; | ||
try { | ||
api.namespace.x = 1; | ||
} catch { | ||
errored = true; | ||
} | ||
assert.ok(errored, 'namespace assignment should be preserved'); |
6 changes: 6 additions & 0 deletions
6
test/function/samples/namespace-member-side-effects/call/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
description: 'checks side effects when calling a namespace', | ||
options: { | ||
treeshake: { tryCatchDeoptimization: false } | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/call/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as namespace from './namespace.js'; | ||
|
||
export default { | ||
namespace | ||
}; |
Empty file.
9 changes: 9 additions & 0 deletions
9
test/function/samples/namespace-member-side-effects/call/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import api from './api/index'; | ||
|
||
let errored = false | ||
try { | ||
api.namespace() | ||
} catch { | ||
errored = true; | ||
} | ||
assert.ok(errored, 'namespace call should be preserved') |
3 changes: 3 additions & 0 deletions
3
test/function/samples/namespace-member-side-effects/member-call/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'respects side effects when namespace members are called' | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/member-call/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as namespace from './namespace.js'; | ||
|
||
export default { | ||
namespace | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/member-call/api/namespace.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { sideEffects } from './sideEffects'; | ||
|
||
export function sideEffectFunction() { | ||
sideEffects.push('fn called'); | ||
} |
1 change: 1 addition & 0 deletions
1
test/function/samples/namespace-member-side-effects/member-call/api/sideEffects.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const sideEffects = []; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/namespace-member-side-effects/member-call/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import api from './api/index.js'; | ||
import { sideEffects } from './api/sideEffects'; | ||
|
||
api.namespace.sideEffectFunction(); | ||
|
||
assert.deepStrictEqual(sideEffects, ['fn called']); |
6 changes: 6 additions & 0 deletions
6
test/function/samples/namespace-member-side-effects/missing-access/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
description: 'respects side effects when accessing missing namespace members', | ||
options: { | ||
treeshake: { tryCatchDeoptimization: false } | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/missing-access/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as namespace from './namespace.js'; | ||
|
||
export default { | ||
namespace | ||
}; |
Empty file.
9 changes: 9 additions & 0 deletions
9
test/function/samples/namespace-member-side-effects/missing-access/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import api from './api/index'; | ||
|
||
let errored = false; | ||
try { | ||
api.namespace.missing.foo; | ||
} catch { | ||
errored = true; | ||
} | ||
assert.ok(errored, 'unknown nested member access should be preserved'); |
7 changes: 7 additions & 0 deletions
7
test/function/samples/namespace-member-side-effects/unknown-access/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
description: 'respects side effects when accessing unknown namespace members', | ||
options: { | ||
external: ['external'], | ||
treeshake: { tryCatchDeoptimization: false } | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/function/samples/namespace-member-side-effects/unknown-access/api/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as namespace from './namespace.js'; | ||
|
||
export default { | ||
namespace | ||
}; |
Empty file.
10 changes: 10 additions & 0 deletions
10
test/function/samples/namespace-member-side-effects/unknown-access/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import api from './api/index'; | ||
import { external } from 'external'; | ||
|
||
let errored = false; | ||
try { | ||
api.namespace[external].foo; | ||
} catch { | ||
errored = true; | ||
} | ||
assert.ok(errored, 'unknown nested member access should be preserved'); |