Skip to content

Commit 18a4e25

Browse files
committed
fix(compiler): treat this/super/import.meta as inert in throwsBeforeAwait and handle TSImportEquals/TSModule in bindsName
- Add ThisExpression, Super, and MetaProperty to the inert expression list in throwsBeforeAwait so that `await this.api.get(id)` is not falsely treated as a synchronous throw. - Add TSImportEqualsDeclaration and TSModuleDeclaration to bindsName so that `import Promise = ...` and `namespace Promise` correctly disable Promise combinator trust. - Add regression tests for both fixes.
1 parent dea2c33 commit 18a4e25

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/octane/src/compiler/strong-mode.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ function bindsName(root, name) {
282282
case 'ClassDeclaration':
283283
case 'ClassExpression':
284284
case 'TSEnumDeclaration':
285+
case 'TSImportEqualsDeclaration':
286+
case 'TSModuleDeclaration':
285287
addPatternNames(node.id, bindings, true);
286288
break;
287289
case 'ImportSpecifier':
@@ -2333,6 +2335,9 @@ export function analyzeStrongMode(ast, source, filename, options = {}) {
23332335
switch (node.type) {
23342336
case 'Literal':
23352337
case 'Identifier':
2338+
case 'ThisExpression':
2339+
case 'Super':
2340+
case 'MetaProperty':
23362341
case 'FunctionExpression':
23372342
case 'ArrowFunctionExpression':
23382343
return false;

‎packages/octane/tests/compiler/strong-effects.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ export function App(props) @{
507507
'do-while exits from catch clauses entered only after yielding',
508508
'do { try { setData(await api.get(props.id)); } catch (e) { break; } } while (props.retry); setLoading(false);',
509509
],
510+
[
511+
'awaited calls through this, super and import.meta receivers',
512+
'try { setData(await this.api.get(props.id)); } catch (e) { setError(e); }',
513+
],
510514
])('allows updates in try clauses reached only after yielding: %s', (_label, body) => {
511515
const source = load(body);
512516
expect(compile(source, '/src/App.tsrx', { strong: true }).code).toBe(
@@ -644,6 +648,8 @@ export function App(props) @{
644648
['', 'function wrap(Promise) { return Promise; }'],
645649
['', 'class Promise {}'],
646650
['', 'try {} catch (Promise) {}'],
651+
['import Promise = Bluebird.Promise;', ''],
652+
['', 'namespace Promise { export const resolve = 1; }'],
647653
])(
648654
'does not trust Promise combinator elements when the module binds Promise: %s%s',
649655
(imports, local) => {

0 commit comments

Comments
 (0)