Skip to content

Commit c44db85

Browse files
committed
add tests for optional implicit and implicit.left
1 parent d0fc7a2 commit c44db85

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/lib/languages/js/source-code/source-code.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,5 +3756,65 @@ describe("SourceCode", () => {
37563756
["Foo", "Foo"],
37573757
);
37583758
});
3759+
3760+
it("should not crash if global scope doesn't have `implicit` property", () => {
3761+
const code = "Array = 1; Foo = 1; Promise = 1; Array; Foo; Promise";
3762+
const ast = espree.parse(code, DEFAULT_CONFIG);
3763+
const scopeManager = eslintScope.analyze(ast, {
3764+
ignoreEval: true,
3765+
ecmaVersion: 6,
3766+
});
3767+
3768+
const globalScope = scopeManager.scopes[0];
3769+
delete globalScope.implicit;
3770+
3771+
const sourceCode = new SourceCode({
3772+
text: code,
3773+
ast,
3774+
scopeManager,
3775+
});
3776+
3777+
sourceCode.applyLanguageOptions({
3778+
ecmaVersion: 2015,
3779+
});
3780+
3781+
// should not throw
3782+
sourceCode.finalize();
3783+
});
3784+
3785+
it("should not crash if global scope doesn't have `implicit.left` property", () => {
3786+
const code = "Array = 1; Foo = 1; Promise = 1; Array; Foo; Promise";
3787+
const ast = espree.parse(code, DEFAULT_CONFIG);
3788+
const scopeManager = eslintScope.analyze(ast, {
3789+
ignoreEval: true,
3790+
ecmaVersion: 6,
3791+
});
3792+
const sourceCode = new SourceCode({
3793+
text: code,
3794+
ast,
3795+
scopeManager,
3796+
});
3797+
3798+
const globalScope = sourceCode.scopeManager.scopes[0];
3799+
delete globalScope.implicit.left;
3800+
3801+
sourceCode.applyLanguageOptions({
3802+
ecmaVersion: 2015,
3803+
});
3804+
3805+
// should not throw
3806+
sourceCode.finalize();
3807+
3808+
const { implicit } = globalScope;
3809+
3810+
assert.deepStrictEqual(
3811+
[...implicit.set].map(([name]) => name),
3812+
["Foo"],
3813+
);
3814+
assert.deepStrictEqual(
3815+
implicit.variables.map(({ name }) => name),
3816+
["Foo"],
3817+
);
3818+
});
37593819
});
37603820
});

0 commit comments

Comments
 (0)