|
1 | 1 | /* eslint-disable jsdoc/check-param-names */ |
2 | | -import type { NodePath, Scope } from "@babel/traverse" |
3 | | -import type { ArrayExpression, Block, BlockStatement, CallExpression, File, FunctionDeclaration, Identifier, Node, ObjectExpression } from "@babel/types" |
4 | | -import type { LaxPartial } from "@samual/lib" |
5 | | -import traverse from "@babel/traverse" |
6 | | -import t from "@babel/types" |
7 | | -import { assert } from "@samual/lib/assert" |
8 | | -import { clearObject } from "@samual/lib/clearObject" |
9 | | -import { validDBMethods } from "../constants" |
10 | | -import { getReferencePathsToGlobal } from "./shared" |
| 2 | +import type { NodePath, Scope } from '@babel/traverse'; |
| 3 | +import traverse from '@babel/traverse'; |
| 4 | +import type { |
| 5 | + ArrayExpression, |
| 6 | + Block, |
| 7 | + BlockStatement, |
| 8 | + CallExpression, |
| 9 | + File, |
| 10 | + FunctionDeclaration, |
| 11 | + Identifier, |
| 12 | + Node, |
| 13 | + ObjectExpression |
| 14 | +} from '@babel/types'; |
| 15 | +import t from '@babel/types'; |
| 16 | +import type { LaxPartial } from '@samual/lib'; |
| 17 | +import { assert } from '@samual/lib/assert'; |
| 18 | +import { clearObject } from '@samual/lib/clearObject'; |
| 19 | +import { validDBMethods } from '../constants'; |
| 20 | +import { getReferencePathsToGlobal } from './shared'; |
11 | 21 |
|
12 | 22 | export type TransformOptions = LaxPartial<{ |
13 | 23 | /** 11 a-z 0-9 characters */ uniqueId: string |
@@ -749,10 +759,19 @@ export function transform( |
749 | 759 |
|
750 | 760 | if (object.type == `ObjectExpression`) { |
751 | 761 | for (const property of (object as ObjectExpression).properties) { |
752 | | - if (property.type != `ObjectMethod`) |
| 762 | + if (property.type == `ObjectMethod`) { |
| 763 | + thisIsReferenced ||= replaceAllThisWith(property, scope, thisId) |
753 | 764 | continue |
| 765 | + } |
| 766 | + |
| 767 | + if (property.type == `ObjectProperty` && property.value.type == `FunctionExpression`) { |
| 768 | + // Replace in things like this: function (foo = this.a) |
| 769 | + for (const param of property.value.params) { |
| 770 | + thisIsReferenced ||= replaceAllThisWith(param, scope, thisId) |
| 771 | + } |
754 | 772 |
|
755 | | - thisIsReferenced ||= replaceAllThisWith(property, scope, thisId) |
| 773 | + thisIsReferenced ||= replaceAllThisWith(property.value.body, scope, thisId) |
| 774 | + } |
756 | 775 | } |
757 | 776 | } else { |
758 | 777 | for (const element of (object as ArrayExpression).elements) { |
|
0 commit comments