diff --git a/.oxfmtrc.json b/.oxfmtrc.json index 594e030b4..9fa524588 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -9,6 +9,8 @@ "groups": [["builtin"], ["external"]] }, "ignorePatterns": [ + "*.snap.json", + "typescript-eslint/", "packages/*/CHANGELOG.md", "playground-temp/", "dist/", diff --git a/packages/plugin-rsc/docs/notes/2026-04-04-hoist-variable-shadowing.md b/packages/plugin-rsc/docs/notes/2026-04-04-hoist-variable-shadowing.md new file mode 100644 index 000000000..6de64044f --- /dev/null +++ b/packages/plugin-rsc/docs/notes/2026-04-04-hoist-variable-shadowing.md @@ -0,0 +1,406 @@ +# Hoist: Variable Shadowing Bug in `bindVars` Collection + +## Problem + +`transformHoistInlineDirective` in `src/transforms/hoist.ts` incorrectly binds variables +that are fully shadowed inside the server function by inner block-scoped declarations. + +### Failing cases (all fixed, were labeled `TODO` in `hoist.test.ts`) + +**`shadowing local body over local`** — declaration directly in action's body + +```js +function outer() { + const value = 0 + async function action() { + 'use server' + const value = 0 // declared in action's own body + return value + } +} +``` + +**`shadowing local body and if over local`** — declaration in body + if-block + +```js +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 0 + return value + } + const value = 0 + return value + } +} +``` + +**`shadowing local over local`** — declaration only inside an if-block + +```js +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 0 + return value + } + } +} +``` + +**`shadowing local over local over global`** + +```js +const value = 0 +function outer() { + const value = 0 + async function action() { + 'use server' + if (true) { + const value = 1 + return value + } + } +} +``` + +## Root Cause (periscopic) + +The original periscopic-based code: + +```ts +const scope = analyzed.map.get(node) // returns param scope, not body scope +const bindVars = [...scope.references].filter((ref) => { + const owner = scope.find_owner(ref) // name-string lookup walking upward + return owner && owner !== scope && owner !== analyzed.scope +}) +``` + +Two layered problems: + +1. **Wrong scope anchor:** `analyzed.map.get(functionNode)` returns the param scope. + Body-level `const`/`let` declarations live in a separate child `BlockStatement` scope + in periscopic's model. So `find_owner` is called from the wrong starting point. + +2. **Name-based resolution:** `scope.references` is `Set` and `find_owner` takes + a string. There is no connection between a specific reference occurrence and the scope + that owns it — you can only ask "does ANY declaration of this name live outside?" not + "does THIS specific reference resolve outside?". Shadowing is invisible. + +## Current State + +Periscopic is gone. `hoist.ts` now uses a custom `buildScopeTree` + `getBindVars` +pipeline that records concrete reference identifiers and resolves each one to its +declaring `Scope`. + +This fixed the original shadowing bug. The current `ScopeTree` shape is: + +```ts +type ScopeTree = { + readonly referenceToDeclaredScope: Map + readonly scopeToReferences: Map + readonly nodeScope: Map + readonly moduleScope: Scope +} +``` + +This is no longer the old periscopic-style name-only design. Resolution is per +identifier occurrence, not `findOwner(name: string)`. + +What is still true: + +- declarations are still stored as `Set` on each `Scope` +- reference collection still walks every `Identifier` and classifies it with + `isReferenceIdentifier(...)` +- the implementation still has known edge cases, notably default-parameter + resolution against hoisted `var` declarations in the same function body + +## Current Algorithm + +`buildScopeTree` is a two-phase algorithm: + +1. Walk the AST once to create scopes, collect declarations, and record raw + `{ id, visitScope }` reference candidates. +2. After the walk, resolve each recorded identifier by scanning upward from + `visitScope`, then propagate that identifier to `scopeToReferences` for the + visit scope and all ancestors. + +This is why the original shadowing bug is fixed now: resolution is per identifier +occurrence, and it happens only after all hoisted declarations are known. + +The main implementation trade-off is elsewhere: phase 1 still records candidates by +walking every `Identifier` and asking `isReferenceIdentifier(...)` whether that syntax +position is a real read. + +## Current Limits + +The remaining problems are no longer the original periscopic ones. + +### 1. Generic identifier classification is still brittle + +The current implementation fixes the shadowing bug, but pass 1 still asks a low-level +question: + +> given an arbitrary `Identifier`, is it a reference? + +That forces `isReferenceIdentifier` to know about many ESTree edge cases: + +- `Property`, `MethodDefinition`, `PropertyDefinition` +- import/export specifiers +- destructuring vs object literals +- parameter defaults +- `import.meta` +- labels + +As soon as the helper needs parent/grandparent context, the abstraction is already +showing strain. + +### 2. Some scope/visibility edge cases still need explicit fixups + +The current code has at least one confirmed semantic gap: + +- default parameter expressions incorrectly resolve to hoisted `var` declarations in the + same function body (`param-default-var-hoisting.js`) + +There are also lower-priority modeling gaps noted elsewhere: + +- unconditional `for` / `for-in` / `for-of` scopes +- no `StaticBlock` scope + +## Why Two Phases Still Make Sense + +Two phases are still the right high-level structure because JavaScript hoisting requires +resolution against a complete scope picture. + +Example: + +```js +function action() { + console.log({ foo }) + { + var foo = 123 + } +} +``` + +If lookup happened eagerly, `foo` would be seen before the hoisted declaration was +registered and could be misresolved to an outer scope. Deferring resolution until after +declaration collection avoids that class of bug. + +So the problem is not "two passes". The problem is specifically that the current first +pass still discovers reads by blind identifier classification. + +## Practical Direction + +Frame the problem as: + +> Given `references: Identifier[]` (all reference-position identifiers inside a `use +server` function body), and a way to look up the declaring `Scope` for each one, bind +> exactly those whose declaring scope is neither the module root nor inside the function +> body itself. + +With this framing `getBindVars` is pure data lookup — no walk, no stack, no string +matching: + +```ts +const fnScope = scopeTree.nodeScope.get(fn)! +const references = scopeTree.scopeToReferences.get(fnScope) ?? [] +const bindVars = [ + ...new Set( + references + .filter((id) => id.name !== declName) + .filter((id) => { + const scope = scopeTree.referenceToDeclaredScope.get(id) + return ( + scope !== undefined && + scope !== scopeTree.moduleScope && + isStrictAncestor(scope, fnScope) + ) // scope is in outer fn, not inside + }) + .map((id) => id.name), + ), +] +``` + +This uses the current `ScopeTree` shape shown above. `nodeScope` is the entry point from +AST nodes into `Scope`; after that, `getBindVars` can stay as pure lookup over +`referenceToDeclaredScope` and `scopeToReferences`. + +Keep the good part: + +- declarations are collected before resolution +- references are resolved per identifier occurrence, not by name string + +The practical maintenance goal is: + +- keep the current two-phase `buildScopeTree` shape +- keep `isReferenceIdentifier` close to Vite SSR's `isRefIdentifier` +- document local divergences explicitly when ESTree-walker / fixture coverage requires them +- add fixtures for concrete edge cases instead of jumping to a larger architectural rewrite + +This keeps the implementation easy to compare against a well-known upstream reference, +which is currently more valuable than pursuing a larger refactor. + +## Alternative, Probably Overkill + +An alternative design would avoid the global identifier classifier entirely. + +Instead of asking: + +> "given an arbitrary `Identifier`, is it a reference?" + +it would ask: + +> "for this AST node, which child nodes are read positions?" + +That may be cleaner in the abstract, but it is a meaningfully larger refactor and is +not the recommended next step right now. + +### Sketch + +```ts +function buildScopeTree(ast: Program): ScopeTree { + // pass 1: create scopes, declare names, hoist `var` +} + +function collectReferences(ast: Program, scopeTree: ScopeTree): void { + // pass 2: walk only read/reference positions + // for each Identifier read: + // 1. resolve owner scope + // 2. store identifier -> owner scope + // 3. append identifier to enclosing function scope's references +} +``` + +`getBindVars` would stay the same shape as the current design above: pure lookup over +`scopeToReferences` and `referenceToDeclaredScope`. + +## Why This Might Be Simpler + +### No global identifier classifier + +We can delete the "is this arbitrary `Identifier` a binding?" helper entirely, or reduce +it to a tiny internal helper if one case still wants it. + +### No grandparent hacks + +`Property` ambiguity goes away when traversal is explicit: + +- `ObjectExpression` + - visit `value` + - visit `key` only if `computed` +- `ObjectPattern` + - do not treat the pattern as a read; it belongs to declaration handling + +So object literals and object patterns are separated structurally, not inferred from an +identifier's ancestors. + +### Better fit for the actual question + +The hoist transform does not need a general-purpose "all identifiers in ESTree" oracle. +It needs: + +- declarations, scoped correctly +- reads inside the server function body +- owner scope for each read + +That is a narrower and more maintainable target. + +## If We Ever Do It + +Pass 2 should be a reference visitor over expression positions, not a blind AST scan. +Representative rules: + +- `Identifier` + - record as a read only when reached through a read-position visitor +- `MemberExpression` + - always visit `object` + - visit `property` only if `computed` +- `Property` under `ObjectExpression` + - visit `value` + - visit `key` only if `computed` +- `CallExpression` / `NewExpression` + - visit `callee` + - visit all args +- `ReturnStatement` + - visit `argument` +- `BinaryExpression`, `LogicalExpression`, `UnaryExpression`, `UpdateExpression` + - visit operand expressions +- `ConditionalExpression` + - visit `test`, `consequent`, `alternate` +- `AssignmentExpression` + - visit `right` + - visit `left` only when it contains computed member accesses that read values +- `TemplateLiteral` + - visit all expressions +- `TaggedTemplateExpression` + - visit `tag` and all template expressions +- `AwaitExpression` / `YieldExpression` + - visit `argument` +- `ClassBody` + - for `PropertyDefinition`, visit `value` and `key` only if `computed` + - for `MethodDefinition`, visit `key` only if `computed`; method body is handled by its + own function scope + +This is not a full ESTree spec list yet. It is the shape we want: explicit read +positions, explicit declaration positions. + +## Decision + +Do not over-index on "one pass vs two passes". The better boundary is: + +- pass 1 answers "what names exist in which scopes?" +- pass 2 answers "which reads occur, and what do they resolve to?" + +That split is coherent. The current implementation's weak point is not the existence of +two phases, but the number of syntax edge cases handled by `isReferenceIdentifier`. + +For now, the preferred approach is pragmatic: + +- stay aligned with Vite SSR's reference classifier where possible +- make local divergences explicit in comments and fixtures +- fix concrete semantic bugs without expanding the design surface unnecessarily + +## Reference Repos + +### oxc-walker (`~/code/others/oxc-walker`) + +**Key design — two-pass with frozen scope:** + +1. First pass: build scope tree, record all declarations (hoisting, `var` vs `let`/`const`) +2. `freeze()` — locks scope data +3. Second pass: for each `Identifier` in reference position, walk up scope hierarchy + +`getUndeclaredIdentifiersInFunction` is close but not directly usable — it doesn't +distinguish module-level globals from outer-function-scope closures. We need only the +subset whose owner is strictly between the action and the module root. + +**Compatibility:** targets oxc-parser which outputs ESTree — same as Vite 8's +`parseAstAsync`. `walk()` accepts a pre-parsed AST directly. + +**Relevant helper:** `src/scope-tracker.ts:isBindingIdentifier`. Our local +`isReferenceIdentifier` should stay aligned with its inverse. The concrete gaps found during the +comparison were: + +- `MethodDefinition` and `PropertyDefinition`: non-computed keys are bindings, not + references +- `ExportSpecifier`: `local` is a reference, `exported` is not + +The remaining differences (`RestElement`, `ArrayPattern`, import specifiers, explicit +param handling) are currently harmless for `getBindVars`. + +### Vite `ssrTransform.ts` (`~/code/others/vite/packages/vite/src/node/ssr/ssrTransform.ts`) + +Working ESTree + `estree-walker` scope implementation (lines ~456–760). Uses a live scope +stack during the walk (`scopeMap`, `varKindStack`, `isInScope`) — closer to the target +design. `estree-walker` is already a dep of `plugin-rsc`. + +### periscopic (`~/code/others/periscopic`) + +Dropped as a dep. `extract_identifiers` / `extract_names` copied directly into the +codebase — small, correct, well-tested utilities for extracting binding names from +destructuring patterns. Source: `src/index.js`. diff --git a/packages/plugin-rsc/docs/notes/2026-04-04-scope-unit-tests.md b/packages/plugin-rsc/docs/notes/2026-04-04-scope-unit-tests.md new file mode 100644 index 000000000..65c3efb3f --- /dev/null +++ b/packages/plugin-rsc/docs/notes/2026-04-04-scope-unit-tests.md @@ -0,0 +1,156 @@ +# Task: Unit-test `buildScopeTree` in its own module + +## Goal + +Extract the custom scope analysis from `hoist.ts` into `src/transforms/scope.ts` and add +a comprehensive `scope.test.ts` that tests `buildScopeTree` directly, independent of the +hoist transform. + +This is step 5 of the migration plan in `2026-04-04-hoist-variable-shadowing.md`. + +## Steps + +### 1. Extract `scope.ts` from `hoist.ts` ✅ + +Done. `src/transforms/scope.ts` exists; `hoist.ts` imports from it. + +### 2. File-based fixture tests in `scope.test.ts` + +Modelled after `oxc_semantic`'s approach: fixture input files paired with snapshot files +capturing a human-readable visualization of the scope tree. + +#### Fixture sources + +Two fixture directories: + +``` +src/transforms/fixtures/scope/typescript-eslint/ ← copied from oxc_semantic's fixtures +src/transforms/fixtures/scope/ ← hand-crafted cases not covered above +``` + +**`typescript-eslint/`** is copied from: +`https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/scope-manager/tests/fixtures` + +These inputs are authoritative: written by people who know the spec, with variable names +like `unresolved` and `dontReference2` that encode the expected behavior in the code itself. + +Historical note: `oxc` also mirrors this fixture corpus in +`crates/oxc_semantic/tests/fixtures/typescript-eslint/`. The introducing commit there is +`48724a0d44c7d10da97f3c0cb714890e965c4ab8` (`chore(semantic): copy tests from +typescript-eslint’s scope-manager (#3990)`), which cites +`https://github.com/typescript-eslint/typescript-eslint/tree/a5b652da1ebb09ecbca8f4b032bf05ebc0e03dc9/packages/scope-manager/tests/fixtures`. + +The checked-in subtree is **pre-transpiled JS**, not TS/TSX. The source of truth is the +local `typescript-eslint` checkout. The reproducible import/update workflow lives in +`packages/plugin-rsc/scripts/README.md`. + +#### Test runner + +```ts +import { parseAstAsync } from 'vite' + +// discover pre-transpiled .js fixture files recursively +for (const file of globSync('**/*.js', { cwd: fixtureDir })) { + it(file, async () => { + const input = readFileSync(path.join(fixtureDir, file), 'utf-8') + const ast = await parseAstAsync(input) + const scopeTree = buildScopeTree(ast) + const snapshot = serializeScopeTree(ast, scopeTree) + await expect(snapshot).toMatchFileSnapshot( + path.join(fixtureDir, file + '.snap'), + ) + }) +} +``` + +#### Snapshot format + +Scope-tree-centric JSON. Each scope node lists its declarations and the direct +references resolved within it. References show the name and which scope they resolve +to via a stable path label (not numeric IDs). + +Example — `shadowing-block.js`: + +```js +function outer() { + const value = 0 + function action() { + if (true) { + const value = 1 + return value + } + } +} +``` + +`shadowing-block.js.snap.json`: + +```json +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": ["value"], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:action", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": ["value"], + "references": [ + { + "name": "value", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement > FunctionDeclaration:action > BlockStatement > BlockStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] + } + ] +} +``` + +The `declaredAt` path is built from scope-creating node labels (function names where +available), disambiguated with `[2]` suffixes for same-type siblings. +`null` means the identifier is global (not declared anywhere in the file). + +#### Hand-crafted fixtures (gaps not covered by typescript-eslint set) + +- `export-specifier.js` — `export {foo as bar}`: `foo` IS resolved, `bar` is NOT +- `label.js` — label in `break`/`continue` NOT a ref +- `shadowing-block.js` — the motivating bug from the migration notes +- `import-meta.js` — `import` / `meta` in `import.meta` are NOT refs +- `param-default-var-hoisting.js` — documents the current default-param + hoisted-`var` + misresolution as a known gap + +### 3. Verify `hoist.test.ts` still passes after the extraction + +## Non-goals + +- Do not change behaviour of `buildScopeTree` in this task. +- Do not implement the pass-2 refactor (replacing `isReferenceIdentifier` with explicit + reference visitor) — that is a separate follow-up described in the migration plan. diff --git a/packages/plugin-rsc/docs/notes/2026-04-05-scope-manager-research.md b/packages/plugin-rsc/docs/notes/2026-04-05-scope-manager-research.md new file mode 100644 index 000000000..fd81ad842 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/2026-04-05-scope-manager-research.md @@ -0,0 +1,187 @@ +# Scope Manager Design Research + +## Goal + +Survey how prior-art JS/TS toolchains implement scope analysis, compare against our custom `buildScopeTree` in `src/transforms/scope.ts`, and extract design lessons that could inform a future refactor (especially the pass-2 reference-visitor proposed in `2026-04-04-hoist-variable-shadowing.md`). + +## Context + +We rolled our own scope analyzer because our use case is narrow: + +- ESTree input (Vite's `parseAstAsync` / oxc-parser) +- Module scope only (no global, no TypeScript types) +- Output needed: for each `use server` function, which outer-scope identifiers does it close over? (`getBindVars` in `hoist.ts`) + +No existing library fit exactly: periscopic had a shadowing bug (wrong scope anchor + name-string resolution), typescript-eslint is TS-AST-only and far heavier than needed, and eslint-scope targets a superset of concerns. + +## Prior Arts + +Each document below covers one implementation: data model, scope types, resolution strategy, and a diff against our approach. + +- [typescript-eslint scope-manager](scope-manager-research/typescript-eslint.md) +- [periscopic](scope-manager-research/periscopic.md) +- [vite ssr transform](scope-manager-research/vite-ssr.md) +- [eslint-scope](scope-manager-research/eslint-scope.md) +- [babel traverse](scope-manager-research/babel-traverse.md) +- [oxc_semantic](scope-manager-research/oxc.md) +- [oxc-walker](scope-manager-research/oxc-walker.md) +- [next.js server action transform](scope-manager-research/nextjs.md) + +## Bugs and gaps found in our implementation + +Discovered by comparing against prior arts. Add test fixtures and fix separately. + +### Bug: default parameter + `var` hoisting (spec violation) + +Discovered via eslint-scope's `__isValidResolution` guard. + +```js +function outer() { + const y = 'outer' + async function action() { + 'use server' + function inner(x = y) { + // which `y` does this resolve to? + var y = 'inner' // hoisted to inner's function scope + } + } +} +``` + +Our post-walk resolver adds `var y` to `inner`'s function scope (via `getNearestFunctionScope()`). When resolving the `y` reference in the default param, `visitScope` is also the function scope, so we immediately find `y` there and return it as the declaring scope. + +Per spec, when a function has non-simple parameters (defaults/destructuring/rest), default param expressions cannot see `var` declarations in the function body — they are in separate environments. The correct resolution is `outer`'s `y`. + +**Practical impact for `getBindVars`:** we would fail to include `outer.y` as a closure variable for `action`, producing a server action that doesn't bind `y` at the call site even though the runtime would capture `outer.y`. + +**Fix direction:** after resolving a reference, if the reference position is a default parameter expression and the resolved scope is the same function scope, re-resolve from the function scope's parent instead. This is what eslint-scope does via a source-position range check (`ref.identifier.range[0] < bodyStart && variable.defs[].range[0] >= bodyStart`). + +### Gap: `for`-loop scope created unconditionally + +eslint-scope and oxc_semantic only create a block scope for `for`/`for-in`/`for-of` loops when the init/left uses `let`/`const`. We create a scope for all for-loops regardless. + +For `for (var i = 0; ...)`, our for-loop scope is empty (since `var i` hoists out), so this causes no wrong results — just a spurious empty scope node in the tree. Low priority. + +### Gap: no `StaticBlock` scope + +`class Foo { static { const x = 1 } }` — the static block creates its own scope in all prior arts (eslint-scope, oxc_semantic, vite-ssr). We don't handle it. Unlikely to matter for `use server` since class instance methods are rejected, but `static` initializers could theoretically contain a server action in future. + +## Bugs found in prior arts + +### oxc-walker: computed member expression misclassified as binding + +`isBindingIdentifier` checks `parent.type === "MemberExpression"` with no guard on `computed`: + +```ts +case "MemberExpression": + return parent.property === node // no !parent.computed check +``` + +This means `obj[bar]` — `bar` is classified as a **binding** (not a reference), so it would never appear in `getUndeclaredIdentifiersInFunction`'s output even if `bar` is an outer-scope variable. Our implementation correctly gates on `!parent.computed`. + +### periscopic: named class expression name leaks to outer scope + +`(class Foo {})` creates no inner scope, so `Foo` is added directly to the current scope's `declarations`. Any outer-scope reference to `Foo` after the expression would resolve to the class, which is incorrect — per spec, `Foo` is only visible inside the class body. + +### periscopic: spurious scope for re-export declarations + +`export { x } from './y'` creates a block scope (`Scope(block=true)`) containing the specifier identifiers as declarations. The re-exported names are not actually declared in this module, so they should not appear in any scope's declarations. + +### vite-ssr: no `switch` scope + +`let`/`const` declared inside a `switch` body are not scoped to the `switch` — they use whatever enclosing block scope exists. In practice this is usually correct (the `switch` body is often already inside a `BlockStatement` function body), but `let` at the top level of a switch case leaks to the enclosing function scope in vite-ssr's model. + +### Next.js: function parameters assumed used (documented TODO) + +From `server_actions.rs` line 340: + +```rust +// TODO: For the current implementation, we don't track if an +// argument ident is actually referenced in the function body. +// Instead, we go with the easy route and assume defined ones are used. +``` + +A server action function parameter that is never referenced in the body is still included in the encrypted closure arg list, adding unnecessary payload size. + +## Comparison table + +| | periscopic | vite-ssr | eslint-scope | babel-traverse | oxc_semantic | oxc-walker | next.js | typescript-eslint | **ours** | +| ---------------------- | ----------------- | ---------------- | --------------------------- | ------------------- | -------------------- | --------------------- | ----------------- | --------------------------- | ----------------------- | +| AST format | ESTree | ESTree | ESTree | Babel AST | oxc AST | ESTree (oxc) | SWC AST | TSESTree | ESTree | +| Language | JS | TS | JS | JS | Rust | TS | Rust | TS | TS | +| Variable object | no | no | yes | yes (Binding) | yes (Symbol, SoA) | no | no | yes | no | +| Read/write flag | no | no | yes | yes | yes (ReferenceFlags) | no | no | yes | no | +| Resolution timing | single-pass (bug) | two-pass | close-time | close-time (lazy) | post-walk | two-pass | two-phase flat | close-time | post-walk | +| Refs aggregated upward | no | no | no (through[]) | no | no | no | no | no (through[]) | yes (scopeToReferences) | +| `var` hoisting | buggy | yes | yes | yes | yes | no (documented gap) | implicit (SWC) | yes | yes | +| Named fn-expr scope | name in fn scope | name in fn scope | FunctionExpressionNameScope | name in fn scope | name in fn scope | two scopes (outer+fn) | N/A (SWC hygiene) | FunctionExpressionNameScope | name in fn scope | +| Class scope | none | named-expr only | ClassScope (always) | ClassScope (always) | ClassScope (always) | scope for name only | not modeled | ClassScope (always) | named-expr only | +| TypeScript support | no | no | no | yes (Babel plugins) | yes | partial | yes (SWC) | yes | no | + +## Related notes + +- [`2026-04-04-hoist-variable-shadowing.md`](2026-04-04-hoist-variable-shadowing.md) — the shadowing bug that motivated the custom implementation and the proposed pass-2 refactor +- [`2026-04-04-scope-unit-tests.md`](2026-04-04-scope-unit-tests.md) — fixture test plan + +## Subagent prompts + +Each prior art was researched by an Explore subagent. Prompts are recorded here for reproducibility. + +### Standard template (all except next.js) + +Replace `{LOCATION}`, `{FRAMING_NOTE}`, and `{EXTRA_QUESTIONS}` per the addendum table below. + +``` +Read and summarize the scope analysis implementation in {LOCATION}. +I need a thorough technical comparison against a custom ESTree scope analyzer. +{FRAMING_NOTE} +Key questions to answer: +1. What is the Scope data model? (fields, types) +2. How are declarations stored? (Set of names, or richer objects?) +3. How are references stored? (Set, or per-Identifier?) +4. How does reference resolution work? (single-pass or two-pass? when does resolution happen relative to declarations?) +5. What scope-creating AST nodes get their own Scope? (functions, blocks, catch, for-loops, classes, named fn expressions?) +6. How does it handle `var` hoisting? +7. How does it handle named function expressions (e.g. `(function f() {})` — does `f` go in the outer scope or the function scope)? +8. How does it handle class scopes? +9. What is the public API surface? +10. What are the known limitations / design trade-offs? +{EXTRA_QUESTIONS} +Please return raw findings — exact field names, code snippets, file paths with line numbers. +I'll write the comparison doc myself. +``` + +**Addendum per prior art:** + +| Prior art | GitHub | `{LOCATION}` (local clone) | `{FRAMING_NOTE}` | `{EXTRA_QUESTIONS}` | +| -------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| periscopic | [Rich-Harris/periscopic](https://github.com/Rich-Harris/periscopic) | `~/code/others/periscopic/` — please read all relevant source files | _(omit)_ | `11. What do extract_names / extract_identifiers do?` | +| vite-ssr | [vitejs/vite](https://github.com/vitejs/vite) | `~/code/others/vite/packages/vite/src/node/ssr/ssrTransform.ts` — the scope-related code is approximately lines 456–760 but check the actual line range yourself | _(omit)_ | `11. Is there a Scope class or is it ad-hoc maps/stacks?` `12. What is the purpose of this scope analysis within ssrTransform — what question is it answering?` `13. The file uses estree-walker — check what version/API it uses.` | +| eslint-scope | [eslint/js](https://github.com/eslint/js) | `~/code/others/eslint-js/packages/eslint-scope/` | _(omit)_ | `11. What is the Variable data model? (defs, references, identifiers)` `12. What is the Reference data model? (identifier, resolved, flag, from)` `13. List all ScopeType variants.` `14. Is there a FunctionExpressionNameScope?` | +| babel-traverse | [babel/babel](https://github.com/babel/babel) | `~/code/others/babel/packages/babel-traverse/src/scope/` | _(omit)_ | `11. What is the Binding data model? (identifier, path, scope, kind, references, referencePaths, constantViolations)` `12. Is resolution lazy or eager (crawl-on-demand)?` `13. List the public scope query API (getBinding(), hasBinding(), etc.)` | +| oxc_semantic | [oxc-project/oxc](https://github.com/oxc-project/oxc) | `~/code/others/oxc/crates/oxc_semantic/src/` | `This is Rust code — focus on the data model and algorithm, not language-specific syntax.` | `11. How are symbols stored? (arena IDs, string interning, etc.)` `12. What is the entry point from the compiler pipeline?` `13. What are the design trade-offs vs JS implementations?` | +| oxc-walker | [oxc-project/oxc-walker](https://github.com/oxc-project/oxc-walker) | `~/code/others/oxc-walker/src/scope-tracker.ts` (and any related files) | _(omit)_ | `11. What is isBindingIdentifier — what positions does it exclude?` `12. What is the public API surface (getUndeclaredIdentifiersInFunction or similar)?` | + +--- + +### next.js (different structure — file discovery first) + +``` +Find and summarize the scope analysis / reference tracking used in Next.js's +server action transform. Repo: https://github.com/vercel/next.js (cloned at `~/code/others/next.js/`). + +First, locate the relevant files — likely somewhere under `packages/next/src/` +involving "server action", "use server", or similar. Check both SWC transform +wrappers and any JS/TS-side analysis. + +Key questions to answer: +1. Does Next.js implement its own scope analysis, or delegate to a library (e.g. babel-traverse, swc)? +2. If custom: what is the data model? what are the scope-creating nodes? how are references resolved? +3. If delegated: which library, which API, and what question is it asking? +4. What specific problem is the scope analysis solving — finding closure variables, rewriting bindings, etc.? +5. How does it handle `var` hoisting, named function expressions, class scopes? +6. What are the known limitations or edge cases handled specially? + +Please return raw findings — exact file paths with line numbers, function names, code snippets. +I'll write the comparison doc myself. +``` diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/babel-traverse.md b/packages/plugin-rsc/docs/notes/scope-manager-research/babel-traverse.md new file mode 100644 index 000000000..ba36a2e8c --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/babel-traverse.md @@ -0,0 +1,242 @@ +# scope.ts vs Babel traverse Scope: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/babel/babel](https://github.com/babel/babel) — `packages/babel-traverse/src/scope/` + +Babel's `Scope` is the most feature-rich JS-side scope implementation in this survey. It is tightly coupled to `NodePath` (Babel's AST cursor with parent tracking), which enables capabilities like AST mutation, identifier renaming, and constant-violation tracking that a read-only scope analyzer cannot provide. + +--- + +## Data model + +### Ours + +```ts +Scope (class) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### Babel + +```ts +Scope + uid: number // unique instance id + path: NodePath // path to scope-creating node + block: t.Scopable // AST node + bindings: { [name: string]: Binding } // declarations in this scope + references: { [name: string]: true } // names referenced here + globals: { [name: string]: t.Identifier } // undeclared identifiers + uids: { [name: string]: boolean } // generated unique ids + data: { [key: string|symbol]: unknown } // arbitrary plugin storage + labels: Map> + +Binding + identifier: t.Identifier // the declaration identifier node + scope: Scope // owning scope + path: NodePath // path to the binding site + kind: BindingKind // "var" | "let" | "const" | "module" | + // "hoisted" | "param" | "local" | "unknown" + constant: boolean // false if ever reassigned + constantViolations: NodePath[] // paths where binding is written after init + referenced: boolean // has been used at least once + references: number // reference count + referencePaths: NodePath[] // path to each reference site + hasValue: boolean // for constant propagation + value: any +``` + +**Key difference:** Babel is `Binding`-centric and `NodePath`-centric — every reference is stored as a `NodePath` (not just an `Identifier` node), giving full AST ancestry context. Our model stores `Identifier` nodes; Babel stores `NodePath` objects which additionally carry parent, grandparent, scope, and mutation APIs. + +--- + +## BindingKind + +Babel distinguishes 8 declaration kinds, which map to JS semantics: + +| Kind | When used | +| ----------- | ----------------------------------------------------------------------- | +| `"var"` | `var` declarator | +| `"let"` | `let` declarator, catch clause param, class declaration id | +| `"const"` | `const`/`using` declarator | +| `"module"` | import specifier | +| `"hoisted"` | function declaration id (hoisted to function scope) | +| `"param"` | function parameter | +| `"local"` | function expression id, class expression id (self-binding, scope-local) | +| `"unknown"` | export specifier | + +--- + +## Scope types created + +Babel defines a `Scopable` union of all scope-creating node types. Notably broader than ours: + +| Node | Ours | Babel | +| ------------------------------------------------------------------ | ----------------------- | ------------------------------------------------- | +| Program | moduleScope | Scope | +| FunctionDeclaration / FunctionExpression / ArrowFunctionExpression | Scope(isFunction=true) | Scope | +| ObjectMethod / ClassMethod / ClassPrivateMethod | not handled | Scope | +| BlockStatement | Scope(isFunction=false) | Scope | +| CatchClause | Scope(isFunction=false) | Scope | +| ForStatement / ForInStatement / ForOfStatement | Scope(isFunction=false) | Scope | +| DoWhileStatement / WhileStatement | not handled | Scope | +| SwitchStatement | Scope(isFunction=false) | Scope | +| ClassDeclaration / ClassExpression | named-expr only | Scope | +| StaticBlock | not handled | Scope | +| TSModuleBlock | not handled | Scope | +| Pattern (fn params) | handled inside fn scope | Scope (when direct child of Function/CatchClause) | + +Notably, Babel does NOT create a separate `FunctionExpressionNameScope` — the function expression name is a `"local"` binding inside the function's own scope, same as our implementation. + +--- + +## Named function expressions and class expressions + +Both put the self-reference name into the node's **own scope** as kind `"local"`: + +```js +;(function f() {})( + // f → kind:"local" in the function scope + class Foo {}, +) // Foo → kind:"local" in the class scope +``` + +This matches our implementation and differs from eslint-scope / typescript-eslint which use a separate `FunctionExpressionNameScope`. + +--- + +## Class scopes + +Class declarations get a `Scope`, but their name binding has an unusual aliasing behavior: + +```ts +// ClassDeclaration id is registered as kind "let" in the PARENT scope +// Inside the class scope, the name is set as an alias to the parent binding: +path.scope.bindings[name] = path.scope.parent.getBinding(name) +``` + +So `Foo` in `class Foo {}` appears in both scopes but the class scope entry is just a pointer to the parent scope's `Binding` object — not a new `Binding`. Class expressions use `"local"` and do create an independent binding inside the class scope. + +--- + +## Resolution: lazy crawl on demand + +Babel uses **lazy initialization** — a scope is only crawled when first accessed: + +```ts +init() → crawl() // called from path.setScope() on first visit +``` + +The `crawl()` algorithm is two-phase: + +**Phase 1 (declaration collection):** Traverse the scope's subtree with `collectorVisitor`. Declarations are registered immediately as `Binding` objects. `var` and function declarations are hoisted to the nearest function/program scope via `getFunctionParent()`. + +**Phase 2 (reference resolution):** After the traversal, iterate `state.references` and call `scope.getBinding(name)` for each — this walks up the parent chain. Resolved references are added to `binding.referencePaths`; unresolved go to `programParent.globals`. + +```ts +for (const ref of state.references) { + const binding = ref.scope.getBinding(ref.node.name) + if (binding) { + binding.reference(ref) // adds NodePath to binding.referencePaths + } else { + programParent.addGlobal(ref.node) + } +} +``` + +This is structurally the same two-phase approach as ours (collect declarations → resolve references). The key difference is timing: Babel crawls lazily when a scope is first touched during traversal, not at the end of a full tree walk. + +--- + +## `var` hoisting + +`var` declarations are explicitly hoisted to `getFunctionParent() || getProgramParent()` during collection: + +```ts +// non-block-scoped declarations: +const parent = path.scope.getFunctionParent() || path.scope.getProgramParent() +parent.registerDeclaration(path) + +// var in for-loop: +const parentScope = scope.getFunctionParent() || scope.getProgramParent() +parentScope.registerBinding('var', declar) +``` + +This is equivalent to our `getNearestFunctionScope()` call. + +--- + +## `var` in loops marked non-constant + +A `var` (or `hoisted`) binding declared inside a loop is automatically marked as non-constant: + +```ts +if ((kind === 'var' || kind === 'hoisted') && isDeclaredInLoop(path)) { + this.reassign(path) // constant = false, path added to constantViolations +} +``` + +Our implementation doesn't track constancy at all. + +--- + +## Public API (scope queries) + +```ts +// Binding lookup (walks parent chain) +scope.getBinding(name): Binding | undefined +scope.getOwnBinding(name): Binding | undefined +scope.hasBinding(name, opts?): boolean +scope.hasOwnBinding(name): boolean +scope.parentHasBinding(name, opts?): boolean + +// Scope hierarchy +scope.getProgramParent(): Scope +scope.getFunctionParent(): Scope | null +scope.getBlockParent(): Scope + +// Binding mutation +scope.registerBinding(kind, path): void +scope.removeBinding(name): void +scope.moveBindingTo(name, scope): void +scope.rename(oldName, newName?): void // AST-aware rename across all references +scope.push({ id, init?, kind? }): void // inject new variable into scope + +// UID generation +scope.generateUid(name?): string +scope.generateUidIdentifier(name?): t.Identifier + +// Plugin data +scope.setData(key, val): void +scope.getData(key): any +``` + +The `rename()` API is particularly powerful — it traverses the scope subtree and rewrites all reference sites, skipping nested scopes that shadow the binding. + +--- + +## What Babel has that we don't + +- **`Binding` with `referencePaths`** — every reference is a `NodePath` with full mutation capabilities. +- **`constantViolations`** — tracks exactly where a binding is written after initialization. +- **`constant` flag** — derived fact useful for optimization (constant folding, inlining). +- **`binding.kind`** — 8 declaration kinds including `"hoisted"`, `"local"`, `"module"`. +- **`scope.rename()`** — AST-aware identifier renaming across all reference sites. +- **`scope.generateUid()`** — unique identifier generation that avoids collisions. +- **`scope.push()`** — inject new variable declarations into a scope. +- **Lazy crawl** — scopes only analyzed when needed, not upfront. +- **Plugin data store** (`scope.setData/getData`) — shared state across visitors. +- **`DoWhileStatement`/`WhileStatement` scopes.** + +## What we have that Babel doesn't + +- **`scopeToReferences` aggregation** — O(1) "all refs inside scope X" without a walk. +- **ESTree input** — Babel operates on its own AST format, not ESTree. Our implementation works directly with Vite's `parseAstAsync` output. +- **Simplicity** — ~300 lines, no NodePath coupling, no mutation API, no lazy crawl machinery. diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/eslint-scope.md b/packages/plugin-rsc/docs/notes/scope-manager-research/eslint-scope.md new file mode 100644 index 000000000..964a2d4c3 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/eslint-scope.md @@ -0,0 +1,192 @@ +# scope.ts vs eslint-scope: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/eslint/js](https://github.com/eslint/js) — `packages/eslint-scope/` + +eslint-scope is the original ECMA-262 scope analyzer for ESTree ASTs that typescript-eslint was built on top of. The interface it defines (`ScopeManager`, `Scope`, `Variable`, `Reference`) became the standard that all subsequent JS scope tools reference. + +--- + +## Data model + +### Ours + +```ts +Scope (class) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### eslint-scope + +```js +Scope + type: string // one of 12 ScopeType variants + block: ESTree.Node // the AST node that created this scope + upper: Scope | null // parent scope + childScopes: Scope[] + isStrict: boolean + variables: Variable[] // declarations in this scope + set: Map // name → Variable + references: Reference[] // references created in this scope + through: Reference[] // unresolved refs delegated to parent + variableScope: Scope // nearest function/global/module scope (for var) + functionExpressionScope: boolean // true only for FunctionExpressionNameScope + dynamic: boolean // true for global/with scopes + directCallToEvalScope: boolean + thisFound: boolean + +Variable + name: string + scope: Scope + identifiers: ESTree.Identifier[] // all declaration nodes + references: Reference[] // all uses + defs: Definition[] // where declared (with kind/node/parent) + +Reference + identifier: ESTree.Identifier // the specific identifier node + from: Scope // scope where the reference appears + resolved: Variable | null // null = global/undeclared + flag: READ=1 | WRITE=2 | RW=3 + writeExpr?: ESTree.Expression // rhs if write + init?: boolean // is this an initializer write + +Definition + type: string // CatchClause | Parameter | FunctionName | ClassName | Variable | ImportBinding + name: ESTree.Identifier + node: ESTree.Node // enclosing declaration node + parent?: ESTree.Node // statement node + kind?: "var" | "let" | "const" +``` + +**Key difference:** eslint-scope is Variable-centric — a `Variable` groups all declaration sites (`defs`, `identifiers`) and all use sites (`references`) for one name. Our model has no `Variable` objects; we map each `Identifier` directly to the `Scope` that declares it. + +--- + +## Scope types + +All 12 `ScopeType` variants: + +| Type | Node | Notes | +| ---------------------------- | ------------------------------------------------------------------ | ------------------------------------------------- | +| `"global"` | Program | root scope | +| `"module"` | Program | in ES module context, child of global | +| `"function"` | FunctionDeclaration / FunctionExpression / ArrowFunctionExpression | | +| `"function-expression-name"` | FunctionExpression (named) | contains only the fn name | +| `"block"` | BlockStatement | ES6+ only | +| `"catch"` | CatchClause | | +| `"with"` | WithStatement | | +| `"for"` | For/ForIn/ForOf | only when init/left has `let`/`const` (not `var`) | +| `"switch"` | SwitchStatement | ES6+ | +| `"class"` | ClassDeclaration / ClassExpression | always created | +| `"class-field-initializer"` | PropertyDefinition value | each field initializer has own scope | +| `"class-static-block"` | StaticBlock | | + +Notable: `for` scope only created for `let`/`const` loops — a `var` for-loop does not get a ForScope. Our implementation creates a scope for all for-loops. + +--- + +## FunctionExpressionNameScope + +Yes — same as typescript-eslint, which inherited this design. A named function expression creates **two** scopes: + +``` +outer scope +└── FunctionExpressionNameScope ← contains only: f (type "function-expression-name") + └── FunctionScope ← contains: params, var declarations +``` + +```js +// (function f() {}) creates: +// 1. FunctionExpressionNameScope { variables: [Variable{name:"f"}] } +// 2. FunctionScope { variables: [params...] } +``` + +Our implementation puts `f` directly into the function scope. Functionally equivalent for resolution but different structural shape. + +--- + +## Class scopes + +A `ClassScope` is created for every class (declaration and expression). The class name is declared **twice**: once in the outer scope (for declarations), and once inside the `ClassScope` (self-reference): + +```js +class Foo extends Base {} +// outer scope ← Foo defined here (ClassDeclaration) +// └── ClassScope ← Foo also defined here (inner self-reference) +``` + +Each class field initializer additionally gets its own `ClassFieldInitializerScope`. + +--- + +## Reference resolution: close-time bubble-up + +1. During the walk, `scope.__referencing(identifier)` adds a `Reference` to `scope.__left`. +2. When a scope closes, `scope.__close()` iterates `__left` and tries to resolve each ref via `scope.__resolve()` — a direct lookup in `scope.set`. +3. Unresolved refs are passed to the parent via `scope.__delegateToUpperScope(ref)`, which adds them to the parent's `through[]` and `__left`. +4. This repeats up the chain until reaching GlobalScope, where unresolved refs become implicit globals. + +Because declarations are registered during the walk (before close), all local declarations are visible when `__close()` runs — this correctly handles `var` hoisting and function declarations within the same scope. + +Our post-walk loop achieves the same result differently: we collect `{ id, visitScope }` pairs during the walk and resolve them all in one pass after the walk is complete. + +**Default parameter edge case:** eslint-scope has special logic in `FunctionScope.__isValidResolution()` that prevents references in default parameter expressions from resolving to variables declared in the function body (references at position < body start cannot resolve to declarations at position >= body start). Our implementation doesn't handle this. + +--- + +## `var` hoisting + +`var` declarations are registered directly into `scope.variableScope` (the nearest function/global/module scope) rather than the current block scope: + +```js +// in referencer.js: +const variableTargetScope = + node.kind === 'var' + ? this.currentScope().variableScope // hoist + : this.currentScope() // let/const stay local +``` + +`variableScope` is set at scope construction time — for function/global/module scopes it points to self; for block scopes it points upward to the nearest function scope. This is equivalent to our `getNearestFunctionScope()`. + +--- + +## Public API + +```js +analyze(tree, options) → ScopeManager + +ScopeManager + .scopes: Scope[] + .globalScope: GlobalScope + .acquire(node, inner?): Scope | null // scope for a node + .release(node, inner?): Scope | null // parent scope of a node + .getDeclaredVariables(node): Variable[] // variables declared by a node +``` + +--- + +## What eslint-scope has that we don't + +- `Variable` objects linking all defs and all uses for one name. +- `Reference` read/write flag and `writeExpr` — knows if an identifier is being written. +- `Definition` kind — `var` vs `let` vs `const` vs param vs import vs class name. +- `through[]` — explicit unresolved-reference chain per scope. +- `FunctionExpressionNameScope` — separate scope for function expression name. +- `ClassScope` for every class, `ClassFieldInitializerScope`, `ClassStaticBlockScope`. +- Default-parameter forward-reference guard. +- `with` scope, strict-mode detection. +- `eval()` dynamic scope propagation. + +## What we have that eslint-scope doesn't + +- `scopeToReferences` aggregation — O(1) "all refs inside scope X". +- Simpler data model — no Variable/Definition/Reference class hierarchy. +- Named class expression scope (self-binding correctly isolated without a full ClassScope). diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/nextjs.md b/packages/plugin-rsc/docs/notes/scope-manager-research/nextjs.md new file mode 100644 index 000000000..ea53feb61 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/nextjs.md @@ -0,0 +1,165 @@ +# scope.ts vs Next.js server action transform: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/vercel/next.js](https://github.com/vercel/next.js) — `crates/next-custom-transforms/src/transforms/server_actions.rs` + +--- + +## How it works + +Next.js implements its own **minimal, purpose-built** scope analysis in Rust as part of its SWC custom transform — not delegating to babel-traverse or SWC's generic scope APIs. The transform is embedded directly inside the server action visitor rather than extracted as a reusable module. + +**Problem being solved:** Identify which outer-scope variables a `'use server'` function closes over so they can be serialized (encrypted) and passed as bound arguments at the call site. + +```js +// input +export function Page() { + const api_key = 'secret' + async function action() { + 'use server' + console.log(api_key) + } +} + +// output (simplified) +export const $$RSC_SERVER_ACTION_0 = async function action( + $$ACTION_CLOSURE_BOUND, +) { + const [$$ACTION_ARG_0] = await decryptActionBoundArgs( + '...', + $$ACTION_CLOSURE_BOUND, + ) + console.log($$ACTION_ARG_0) +} +export function Page() { + const api_key = 'secret' + var action = $$RSC_SERVER_ACTION_0.bind( + null, + encryptActionBoundArgs('...', api_key), + ) +} +``` + +This is the same problem as our `getBindVars` — find the closure variables — but implemented at the SWC/Rust layer. + +--- + +## Data model + +### Ours + +``` +Scope (class, JS) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### Next.js + +No `Scope` class. The visitor carries two flat Vecs as mutable state: + +```rust +// on the ServerActions visitor struct (lines 249–250) +names: Vec // reference identifiers collected in current fn body +declared_idents: Vec // declarations collected in current fn body + +// Name = a base identifier + optional member access chain +struct NamePart { prop: Atom, is_member: bool, optional: bool } +struct Name(Id, Vec) +// e.g. `foo.bar?.baz` → Name(foo_id, [.bar, ?.baz]) +// e.g. `x` → Name(x_id, []) +``` + +`Id` is SWC's `(Symbol, SyntaxContext)` pair — the `SyntaxContext` encodes hygiene marks so two bindings named `x` in different scopes are distinguishable without a scope tree. + +There is no scope tree, no parent chain, no node→scope map. The entire analysis is a single function body at a time. + +--- + +## Scope types + +Only **function boundaries** are modeled. Block scopes, catch scopes, class scopes — none of these create a new tracking context: + +| Situation | Next.js | Ours | +| ------------------------------ | ----------------------------------------- | ---------------------------------------- | +| `function f() {}` / `() => {}` | new `declared_idents` snapshot | `Scope(isFunction=true)` | +| `{ }` BlockStatement | not modeled | `Scope(isFunction=false)` | +| `for` / `for…in` / `for…of` | not modeled | `Scope(isFunction=false)` | +| `catch (e)` | not modeled | `Scope(isFunction=false)` | +| `class {}` | not modeled (rejected for `'use server'`) | `Scope(isFunction=false)` for named expr | + +Not modeling block scopes is fine for the specific goal: `var` declarations hoist to function scope anyway, and `let`/`const` inside the server action body should still be treated as "local" (not bound). The filter step (`retain_names_from_declared_idents`) handles this because it keeps only names matching the **outer** function's `declared_idents`. + +--- + +## Resolution strategy + +### Next.js: two-phase, flat, per-function-body + +**Phase 1 (declarations):** While visiting the function body, `visit_mut_param` and `collect_decl_idents_in_stmt` push bindings into `declared_idents`. No tree built — just a flat Vec. + +**Phase 2 (filter):** `retain_names_from_declared_idents` cross-references `names` against the **caller's** `declared_idents` snapshot — keeping only references whose base `Id` matches a declaration from the outer function scope. + +```rust +current_declared_idents + .iter() + .any(|ident| ident.to_id() == name.0) // Id comparison, hygiene-aware +``` + +Shadowing is handled implicitly by SWC's hygiene system: if the inner function re-declares `x`, the inner `x` and outer `x` have different `SyntaxContext` values, so they never match as the same `Id`. + +### Ours: post-walk, full scope tree + +We build a complete scope tree first, then resolve every `Identifier` reference against it. This gives us the answer for any scope, not just the outermost function boundary. + +--- + +## Member access chains (`Name`) + +The `Name` type is a notable addition over our approach. Instead of tracking only the base `Identifier`, Next.js tracks the full member access path: + +```js +async function action() { + 'use server' + console.log(config.api.key) // → Name(config_id, [.api, .key]) +} +``` + +This allows the bound arg to be `config.api.key` (a property read) rather than just `config` (the whole object). The deduplication step then collapses `config` + `config.api.key` → `config` when both appear. + +Our `getBindVars` only tracks the base identifier name, binding the full object even if only one property is used. The `TODO` comment in `scope.ts` acknowledges this as a future extension. + +--- + +## `var` hoisting + +Not explicitly modeled. SWC's parser handles the AST normalization, and the flat declaration collection (`collect_decl_idents_in_stmt`) picks up `var` declarations wherever they appear in the function body — the same effect as hoisting, without needing a two-pass approach. + +--- + +## Known limitations (from source comments) + +- `TODO` at line 340: parameters are assumed used if declared, not checked for actual reference. +- No block scope modeling means `let`/`const` declared in an inner block are not distinguished from outer ones (over-captures in edge cases). +- Only `foo.bar.baz` member chains; no computed properties (`foo[bar]`) or method calls in the bound expression. +- Class instance methods rejected outright — only static methods and top-level functions may have `'use server'`. + +--- + +## What Next.js has that we don't + +- **Member access chain tracking** (`Name` type) — can bind `config.api.key` instead of the whole `config` object. +- **Hygiene-aware Id comparison** — SWC's `SyntaxContext` handles shadowing without needing a scope tree at all. + +## What we have that Next.js doesn't + +- **Full scope tree** — works for any nesting depth, any query (not just "what does this one function close over?"). +- **Block scope modeling** — correct `let`/`const` shadowing within the action body. +- **Language:** JS/TS — no Rust/SWC dependency; works with any ESTree parser. diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/oxc-walker.md b/packages/plugin-rsc/docs/notes/scope-manager-research/oxc-walker.md new file mode 100644 index 000000000..249db3e83 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/oxc-walker.md @@ -0,0 +1,209 @@ +# scope.ts vs oxc-walker: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/oxc-project/oxc-walker](https://github.com/oxc-project/oxc-walker) — `src/scope-tracker.ts` + +oxc-walker is a small TS utility that pairs an AST walker with an optional `ScopeTracker`. It is the most directly comparable prior art to our implementation in terms of scope (pun intended) — both are lightweight, ESTree-compatible, and purpose-built rather than general-purpose compiler infrastructure. + +--- + +## Data model + +### Ours + +```ts +Scope (class) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### oxc-walker + +No `Scope` class. Scopes are keyed by string indices; the tracker is a flat map: + +```ts +scopes: Map> + +// Scope key format: hierarchical dot-separated indices +// root: "" +// first child: "0" +// second child at depth 2: "0-1" +// Built from a depth-first traversal index stack + +// Current scope tracked as: +scopeIndexStack: number[] // e.g. [0, 1, 2] +scopeIndexKey: string // e.g. "0-1" (all but last = current scope key) +``` + +Declarations are **richer objects**, not just strings: + +```ts +type ScopeTrackerNode = + | ScopeTrackerVariable // VariableDeclaration binding — has variableNode + | ScopeTrackerFunctionParam // function parameter — has fnNode + | ScopeTrackerFunction // function declaration/expression id + | ScopeTrackerIdentifier // class name or other identifier + | ScopeTrackerImport // import specifier — has importNode + | ScopeTrackerCatchParam // catch clause parameter — has catchNode + +// All share a BaseNode with: +scope: string // scope key where declared +node: T // original AST node +start: number // source position +end: number +``` + +**Key difference:** oxc-walker uses string-keyed scope indices rather than object references with parent links. To walk up the scope chain you decompose the key string (split on `"-"`, drop the last segment). There is no scope parent pointer. + +--- + +## Scope types created (entries in `scopes` map) + +| Situation | oxc-walker | Ours | +| --------------------------------- | ------------------------------------------------ | ---------------------------------------- | +| Program | `""` root scope | `moduleScope` | +| `function f() {}` | scope for params (name declared in parent scope) | `Scope(isFunction=true)` | +| Named fn expr `(function f() {})` | **two scopes**: outer for name, inner for params | `Scope(isFunction=true)` with `f` inside | +| `() => {}` | scope for params | `Scope(isFunction=true)` | +| `{ }` BlockStatement | scope | `Scope(isFunction=false)` | +| `for` / `for…in` / `for…of` | scope | `Scope(isFunction=false)` | +| `catch (e)` | scope | `Scope(isFunction=false)` | +| Named class expr `(class Foo {})` | scope for name (same pattern as NFE) | `Scope(isFunction=false)` with `Foo` | +| Class declaration | no scope; name declared in parent scope | no scope | +| `switch` | not handled | `Scope(isFunction=false)` | +| Class static block | scope | not handled | + +**Named function expression: two scopes.** This is similar to eslint-scope's `FunctionExpressionNameScope` pattern but implemented as two separate entries in the flat scope map rather than two linked Scope objects: + +``` +"" → (outer scope) +"0" → { f: ScopeTrackerFunction } ← function name scope +"0-0" → { param: ScopeTrackerFunctionParam, ... } ← params scope +"0-0-0"→ (body BlockStatement scope) +``` + +Our implementation puts `f` into the function scope directly (no separate wrapper scope). + +--- + +## Reference detection: `isBindingIdentifier` + +oxc-walker exports `isBindingIdentifier(node, parent)` — a positive classifier that returns `true` when an `Identifier` is a **declaration** (binding position). Anything returning `false` is a reference. This is the inverse of our `isReferenceIdentifier`. + +Positions classified as bindings (excluded from references): + +| Parent | Binding position | +| ---------------------------------------- | ----------------------------------------------- | +| FunctionDeclaration / FunctionExpression | `id`, each identifier in `params` patterns | +| ArrowFunctionExpression | each identifier in `params` patterns (no `id`) | +| ClassDeclaration / ClassExpression | `id` | +| VariableDeclarator | all identifiers in `id` pattern | +| CatchClause | all identifiers in `param` pattern | +| MethodDefinition | `key` | +| PropertyDefinition | `key` | +| Property | `key` when `key !== value` (i.e. not shorthand) | +| MemberExpression | `property` (always — computed or not) | + +This is close to but not identical to our `isReferenceIdentifier`. Key differences noted in `2026-04-04-hoist-variable-shadowing.md`: + +- oxc-walker classifies `MethodDefinition` and `PropertyDefinition` keys as bindings (we do too). +- oxc-walker classifies `MemberExpression.property` as a binding regardless of `computed` — ours only excludes it when `!computed`. This means `obj[bar]` would be mis-classified by oxc-walker (computed properties are references, not bindings). + +Wait — re-reading the source: `parent.property === node` with no `computed` check. This looks like a bug in oxc-walker for computed member expressions, or they assume oxc-parser normalizes this differently. + +--- + +## Resolution strategy + +**No pre-built reference→scope map.** References are not stored at all — the tracker only stores declarations. To check if an identifier is in scope, callers use: + +```ts +scopeTracker.isDeclared(name) // walks up scope key hierarchy +scopeTracker.getDeclaration(name) // same, returns the ScopeTrackerNode +``` + +`isDeclared` reconstructs the ancestor chain by decomposing the key string: + +```ts +const indices = this.scopeIndexKey.split('-').map(Number) +for (let i = indices.length; i >= 0; i--) { + if (this.scopes.get(indices.slice(0, i).join('-'))?.has(name)) return true +} +``` + +For full undeclared-identifier analysis, callers must run **two passes** using `getUndeclaredIdentifiersInFunction`: + +1. Walk with `ScopeTracker` to collect all declarations. +2. Call `scopeTracker.freeze()` to lock declarations. +3. Walk again; for each non-binding `Identifier` call `scopeTracker.isDeclared(name)`. + +This matches our two-phase approach in principle, though we do both phases in a single walk + post-walk loop. + +--- + +## `var` hoisting + +**Not implemented.** `var` declarations are stored in the scope where they textually appear, not hoisted to the nearest function scope. This is documented as a known limitation — the scope model "doesn't mirror JavaScript's scoping 1:1". For the intended use case (finding undeclared identifiers via `getUndeclaredIdentifiersInFunction`) this is sufficient because the question is only "is this name declared anywhere inside this function?" not "which scope owns it." + +--- + +## Public API + +```ts +// Query (during or after walk) +scopeTracker.isDeclared(name: string): boolean +scopeTracker.getDeclaration(name: string): ScopeTrackerNode | null +scopeTracker.getCurrentScope(): string +scopeTracker.isCurrentScopeUnder(scope: string): boolean + +// Lifecycle +scopeTracker.freeze(): void // lock after first pass, reset for second pass + +// Standalone utilities +isBindingIdentifier(node, parent): boolean +getUndeclaredIdentifiersInFunction(fn): string[] + +// Integration with walker +walk(node, { scopeTracker, enter, leave }) +``` + +`getUndeclaredIdentifiersInFunction` is the highest-level API and the closest equivalent to our `getBindVars` — it returns the names of all identifiers referenced but not declared inside a function. The difference: it returns names (`string[]`) not `Identifier` nodes, and doesn't distinguish outer-scope closures from globals (both are "undeclared inside the function"). + +--- + +## Scope deletion by default + +Scopes are deleted from the map when exited unless `preserveExitedScopes: true`: + +```ts +if (!this.options.preserveExitedScopes) { + this.scopes.delete(this.scopeIndexKey) +} +``` + +This means single-pass use only reads the current scope chain. Two-pass analysis requires `preserveExitedScopes: true` so that the frozen declaration map survives into the second walk. + +--- + +## What oxc-walker has that we don't + +- **`ScopeTrackerNode` typed declarations** — knows if a name came from a `var`, param, import, catch, or function declaration. +- **`getUndeclaredIdentifiersInFunction`** high-level utility. +- **`freeze()` / two-pass pattern** — explicit API for multi-pass analysis. +- **Walker integration** — scope tracking is coupled directly into the walk API, so callers don't need to build the scope tree separately. + +## What we have that oxc-walker doesn't + +- **`var` hoisting** — correctly models `var` semantics. +- **`switch` scope.** +- **Per-`Identifier` reference map** (`referenceToDeclaredScope`) — answers "which exact scope declared this specific reference?" not just "is this name declared somewhere?". +- **`scopeToReferences` aggregation** — O(1) "all refs inside scope X". +- **Object parent links** — scope chain is a linked list of `Scope` objects, not a string key decomposition. +- **Distinguishes outer-scope closures from globals** — our `getBindVars` can filter to only bindings from scopes between the server function and the module root. diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/oxc.md b/packages/plugin-rsc/docs/notes/scope-manager-research/oxc.md new file mode 100644 index 000000000..3811e5d02 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/oxc.md @@ -0,0 +1,222 @@ +# scope.ts vs oxc_semantic: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/oxc-project/oxc](https://github.com/oxc-project/oxc) — `crates/oxc_semantic/src/` (Rust) + +oxc_semantic is the full semantic analysis pass of the oxc compiler — the heaviest implementation in this survey. It is designed as production compiler infrastructure, not a library for external callers. + +--- + +## Data model + +### Ours + +```ts +Scope (class) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### oxc_semantic + +**Struct-of-Arrays (SoA) layout** — all symbols stored in parallel arrays indexed by `SymbolId` (u32), all scopes in parallel arrays indexed by `ScopeId` (u32), all references by `ReferenceId` (u32). No heap-allocated objects per symbol/scope/reference. + +```rust +// Core output (Scoping / ScopingInner) + +// Symbols — parallel arrays indexed by SymbolId +symbol_spans: Vec // source position +symbol_flags: Vec // var/let/const/class/fn/import/TS variants… +symbol_scope_ids: Vec // declaring scope +symbol_declarations: Vec // declaring AST node + +symbol_names: ArenaVec // string-interned names (arena allocator) +resolved_references: ArenaVec> // per-symbol reference lists +symbol_redeclarations: FxHashMap> // lazy, only if redeclared + +// Scopes — parallel arrays indexed by ScopeId +parent_ids: Vec> +node_ids: Vec +flags: Vec +bindings: IndexVec> // name → SymbolId per scope + +// References +// per-node reference struct: +Reference { + node_id: NodeId // the IdentifierReference AST node + symbol_id: Option // resolved target; None = unresolved + scope_id: ScopeId // scope where the reference appears + flags: ReferenceFlags // Read | Write | Type | ValueAsType | Namespace +} +root_unresolved_references: ArenaIdentHashMap> // globals +``` + +**Key point:** there are no `Scope` objects or `Symbol` objects on the heap. A "scope" is just an index into several parallel arrays. This is the largest architectural difference from every JS implementation in this survey. + +--- + +## Symbol flags + +`SymbolFlags` covers all JS + TypeScript declaration kinds: + +``` +FunctionScopedVariable | BlockScopedVariable | ConstVariable +Class | Function | CatchVariable +Import | TypeImport +TypeAlias | Interface | RegularEnum | ConstEnum | EnumMember +TypeParameter | NamespaceModule | ValueModule | Ambient +``` + +Composite: `Variable = FunctionScopedVariable | BlockScopedVariable | ConstVariable`, `BlockScoped = BlockScopedVariable | ConstVariable | Class`, etc. + +Ours has none of this — `Set` treats all declaration kinds identically. + +--- + +## Scope types created + +| Situation | oxc_semantic | Ours | +| -------------------------------------------------------------- | ------------------------------------------- | ------------------------- | +| `Program` | `ScopeFlags::Top` | `moduleScope` | +| `function f() {}` / `() => {}` | `ScopeFlags::Function` | `Scope(isFunction=true)` | +| Arrow fn | `ScopeFlags::Function \| Arrow` | `Scope(isFunction=true)` | +| `{ }` BlockStatement | `ScopeFlags::empty()` | `Scope(isFunction=false)` | +| `for` / `for…in` / `for…of` | `ScopeFlags::empty()` | `Scope(isFunction=false)` | +| `catch (e)` | `ScopeFlags::CatchClause` | `Scope(isFunction=false)` | +| `switch` | not created (no separate scope) | `Scope(isFunction=false)` | +| `class {}` | `ScopeFlags::StrictMode` (always one scope) | named-expr only | +| `class {}` static block | `ScopeFlags::ClassStaticBlock` | not handled | +| `with (x) {}` | `ScopeFlags::With` | not handled | +| TypeScript: namespace, interface, type param, conditional type | dedicated flags | not handled | + +**switch** is absent in oxc_semantic (same gap as vite-ssr, opposite of ours). + +--- + +## Named function expressions + +Name binds in the **function's own scope**, same as ours: + +``` +outer scope +└── function scope ← 'f' declared here, same scope as params + └── body +``` + +The function scope is entered before the name is bound (`enter_scope` → `func.bind(self)`), so `f` cannot be seen from the outer scope. If a parameter also named `f` exists, the parameter shadows it — this redeclaration is detected and handled explicitly. + +--- + +## Class scopes + +oxc_semantic creates **one `ClassScope`** for every class (declaration or expression), always: + +```js +class Foo extends Base {} +``` + +``` +outer scope ← Foo declared here (class declaration) +└── ClassScope (StrictMode) ← Foo also declared here (self-reference) +``` + +Named class expression: name binds inside the class scope (not in the outer scope). Anonymous class expression: still creates the `ClassScope`, just no name binding. + +This matches typescript-eslint's `ClassScope` behavior. Our implementation only creates a scope for named class expressions. + +--- + +## Reference resolution + +### Strategy: walk-up with checkpoint-based early resolution + +**Normal resolution** happens in a post-walk pass (`resolve_all_references`): after the entire AST is visited, each unresolved reference walks up the scope chain via `scope_parent_id()` until it finds a `bindings` entry with the matching name. + +**Early (checkpoint) resolution** fires at specific points during the walk to handle forward-reference constraints: + +- After function parameters are visited (before the body) — prevents params from binding to body declarations +- After catch parameters — prevents the catch param from binding to the catch body + +The checkpoint mechanism saves the current position in the flat unresolved-references list; everything before the checkpoint is resolved against the current scope chain, leaving the rest for later. + +This is more nuanced than our single post-walk pass, which resolves everything at once (sufficient because we never need the checkpoint separation). + +### Walk-up vs bubble-up + +typescript-eslint and eslint-scope use a **bubble-up** strategy: each scope maintains a `through[]` / `leftToResolve[]` queue; on scope close, unresolved refs are pushed to the parent. This is N scope-exit operations. + +oxc_semantic uses a **walk-up** strategy: one flat list of unresolved references, each resolved by walking the scope chain at the end. Better cache locality, no per-scope-exit work. + +Our approach is also walk-up (post-walk flat loop), same principle. + +--- + +## `var` hoisting + +Handled during the walk via an explicit hoisting tracker: + +1. When a `var` declaration is encountered, walk up the scope chain collecting block scopes. +2. Stop at the first scope with `flags.is_var()` (Top / Function / ClassStaticBlock / TsModuleBlock). +3. Check for redeclaration in all intermediate scopes via both `bindings` and a side-table `hoisting_variables: FxHashMap>`. +4. Bind the symbol in the target scope. +5. If the binding was temporarily placed in an intermediate scope, move it (`move_binding`). + +The separate `hoisting_variables` side-table is needed so that redeclaration checks during the walk can see hoisted vars even before they've been moved to their final scope. + +Our approach is simpler: at declaration time, call `getNearestFunctionScope()` and add directly to that scope. No side-table needed because we only store names (strings), not node references. + +--- + +## Public API + +```rust +SemanticBuilder::new() + .with_check_syntax_error(bool) + .with_cfg(bool) + .build(&program) + → SemanticBuilderReturn { semantic, errors } + +// Query APIs on Scoping: +scoping.symbol_name(id) // &str +scoping.symbol_flags(id) // SymbolFlags +scoping.symbol_scope_id(id) // ScopeId +scoping.symbol_declaration(id) // NodeId +scoping.get_resolved_references(id) // Iterator<&Reference> +scoping.symbol_is_mutated(id) // bool +scoping.symbol_is_unused(id) // bool +scoping.root_unresolved_references() // globals + +scoping.scope_flags(id) // ScopeFlags +scoping.scope_parent_id(id) // Option +scoping.scope_ancestors(id) // Iterator +scoping.find_binding(scope, name) // Option (walks up) +scoping.get_binding(scope, name) // Option (this scope only) +scoping.iter_bindings_in(scope) // Iterator +``` + +--- + +## What oxc_semantic has that we don't + +- **SoA / arena memory model** — compiler-grade performance, no per-symbol heap allocation. +- **SymbolFlags** — full declaration-kind information (var/let/const/class/fn/import/TS variants). +- **ReferenceFlags** — Read/Write/Type per reference. +- **Redeclaration tracking** — knows when a name is declared more than once and stores all sites. +- **`symbol_is_mutated` / `symbol_is_unused`** — derived facts useful for linting/optimization. +- **TypeScript type-space** — separate type vs value reference tracking. +- **ClassScope always** (not just named expressions), ClassStaticBlock scope. +- **`with` scope**, strict-mode propagation, direct-eval propagation. +- **Checkpoint early resolution** — correct forward-reference semantics for params. + +## What we have that oxc_semantic doesn't + +- **`scopeToReferences` aggregation** — O(1) "all refs inside scope X" without a walk. oxc_semantic has `get_resolved_references(symbol_id)` (per symbol) but no pre-aggregated per-scope list of all references. +- **JS/TS implementation** — works with any ESTree parser; no Rust toolchain required. +- **Simplicity** — ~300 lines vs ~4000+ lines across multiple files. diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/periscopic.md b/packages/plugin-rsc/docs/notes/scope-manager-research/periscopic.md new file mode 100644 index 000000000..3cf53f301 --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/periscopic.md @@ -0,0 +1,162 @@ +# scope.ts vs periscopic: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/Rich-Harris/periscopic](https://github.com/Rich-Harris/periscopic) — `src/index.js` + +--- + +## Data model + +### Ours + +``` +Scope + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### periscopic + +``` +Scope + parent: Scope | null + block: boolean // true = block scope, false = function scope + declarations: Map // name → declaring AST node + initialised_declarations: Set // subset of declarations that have an initializer + references: Set // names referenced here OR in any child scope + +analyze(ast) → { map, scope, globals } + map: WeakMap // scope-creating node → Scope + scope: Scope // root scope + globals: Map // name → Identifier node, for names with no declaration +``` + +**Key difference:** periscopic stores the declaring AST node in `declarations` (richer than our `Set`), but references are only `Set` — no link back to individual `Identifier` nodes. Once you ask "is `foo` referenced?" you get yes/no but cannot identify which `Identifier` nodes produced that answer. This is what makes shadowing invisible (see below). + +--- + +## Scope types created + +| Situation | periscopic | Ours | +| ------------------------------------------------ | ------------------------------------- | ------------------------------------ | +| `function f() {}` / `function() {}` / `() => {}` | `Scope(block=false)` | `Scope(isFunction=true)` | +| Named fn expr `(function f() {})` | `f` added to the function's own scope | same | +| `class Foo {}` (declaration) | no scope | no scope | +| `(class Foo {})` (named expression) | no scope | `Scope(isFunction=false)` with `Foo` | +| `{ }` BlockStatement | `Scope(block=true)` | `Scope(isFunction=false)` | +| `for (…)` / `for…in` / `for…of` | `Scope(block=true)` | `Scope(isFunction=false)` | +| `switch (…)` | `Scope(block=true)` | `Scope(isFunction=false)` | +| `catch (e)` | `Scope(block=true)` | `Scope(isFunction=false)` | +| `export { x } from './y'` | `Scope(block=true)` ← unnecessary | no scope | + +Notable gap: periscopic creates no scope for named class expressions, so the self-binding name `Foo` in `(class Foo {})` leaks to the outer scope. Our implementation fixes this. + +--- + +## Reference detection + +periscopic delegates to the [`is-reference`](https://github.com/nicolo-ribaudo/is-reference) package to decide whether an `Identifier` is a reference. This is equivalent to our `isReferenceIdentifier()` function. Neither implementation re-implements this from scratch — ours is modeled after Vite SSR's `isRefIdentifier`, which is in turn derived from the same lineage. + +--- + +## Reference resolution strategy + +### periscopic: post-walk, name-string resolution + +1. Walk collects `[scope, Identifier]` pairs into a temporary array. +2. After the walk, for each pair call `scope.find_owner(name)` — a name-string lookup walking up the parent chain. +3. Unresolved names go into `globals`. + +`find_owner` is a string-based chain walk: + +```js +find_owner(name) { + if (this.declarations.has(name)) return this; + return this.parent && this.parent.find_owner(name); +} +``` + +This looks correct, but the **scope anchor** used for the lookup is wrong in practice (see shadowing bug below). + +### Ours: post-walk, Identifier-node resolution + +Same two-phase structure, but we store the `Identifier` node itself and resolve against the complete scope tree after the walk. This gives us per-Identifier granularity instead of per-name. + +--- + +## The shadowing bug + +This is why periscopic was dropped as a dependency (see `2026-04-04-hoist-variable-shadowing.md`). + +The original caller did: + +```ts +const scope = analyzed.map.get(functionNode) // returns param scope +const bindVars = [...scope.references].filter((ref) => { + const owner = scope.find_owner(ref) // name-string lookup + return owner && owner !== scope && owner !== analyzed.scope +}) +``` + +Two layered problems: + +**1. Wrong scope anchor.** `analyzed.map.get(functionNode)` returns the scope for the function node itself, which in periscopic's model is the param scope. The function body (`BlockStatement`) is a child scope of this. `let`/`const` declarations inside the body live in that child scope. So when `find_owner` walks up from the param scope it skips the body-scope declarations, and a body-level `const value` becomes invisible — the lookup walks past it and finds the outer `value` instead. + +**2. Name-based references.** `scope.references` is `Set`. There is no way to ask "does this specific reference occurrence resolve inside or outside?" — only "does any declaration of this name exist outside?" A body-scope shadowing declaration is invisible because the reference string `"value"` matches whether it is resolved locally or not. + +Together: a `const value` declared inside the server function body would not prevent the outer `value` from being bound, because (a) the anchor scope didn't see the inner declaration, and (b) even if it had, the string-based check couldn't distinguish "this reference resolves to the inner `value`" from "this reference resolves to the outer `value`". + +--- + +## `var` hoisting + +periscopic handles `var` hoisting by recursively delegating to the parent scope from within `add_declaration`: + +```js +if (node.kind === 'var' && this.block && this.parent) { + this.parent.add_declaration(node) +} +``` + +A `var` in a block scope propagates upward until it lands in a non-block (function) scope. This is correct. + +Our implementation does the same, but at walk time rather than at declaration-adding time: + +```ts +const target = node.kind === 'var' ? current.getNearestFunctionScope() : current +``` + +--- + +## `extract_names` / `extract_identifiers` + +periscopic exports these two utilities. We copied them directly into our codebase (`src/transforms/utils.ts`) rather than keeping the periscopic dependency. They recursively extract leaf binding names from destructuring patterns: + +- `Identifier` → push the name +- `ObjectPattern` → recurse into property values and rest +- `ArrayPattern` → recurse into elements +- `RestElement` → recurse into argument +- `AssignmentPattern` → recurse into left (the binding, not the default) + +These are still used by our `buildScopeTree` for param and destructuring declaration handling. + +--- + +## What periscopic has that we don't + +- `declarations` maps names to the declaring AST node (not just a string set) — useful if callers need to distinguish declaration kind or locate the declaration site. +- `globals` map — explicit set of undeclared names with the referencing `Identifier` node. +- `initialised_declarations` — subset of declarations that had an initializer. + +## What we have that periscopic doesn't + +- Per-`Identifier` reference tracking (not per-name) — makes shadowing correctly visible. +- Named class expression scope (self-binding `Foo` in `(class Foo {})`). +- `scopeToReferences` aggregation — O(1) "all references inside scope X". diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/typescript-eslint.md b/packages/plugin-rsc/docs/notes/scope-manager-research/typescript-eslint.md new file mode 100644 index 000000000..e2fdbeb4c --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/typescript-eslint.md @@ -0,0 +1,186 @@ +# scope.ts vs typescript-eslint scope-manager: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/typescript-eslint/typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) — `packages/scope-manager/` + +--- + +## Data model + +### Ours + +``` +Scope + declarations: Set // names declared here + parent: Scope | undefined + isFunction: boolean // whether this is a function boundary + +ScopeTree + referenceToDeclaredScope: Map // ref id → declaring scope (null = global) + scopeToReferences: Map // scope → all ref ids (propagated upward) + nodeScope: Map // AST node → its scope + moduleScope: Scope +``` + +### typescript-eslint + +``` +ScopeBase + type: ScopeType enum // 18 distinct types + variables: Variable[] // Variables declared here + set: Map // name → Variable + references: Reference[] // References created in THIS scope + through: Reference[] // Unresolved refs delegated to upper scope + childScopes: Scope[] + upper: Scope | null + block: TSESTree.Node // the AST node that created this scope + variableScope: VariableScope // nearest function/module/global scope (for var hoisting) + +Variable + name: string + defs: Definition[] // where it was declared (includes kind: var/let/const/param/...) + references: Reference[] // all uses of this variable + identifiers: Identifier[] // declaration sites + scope: Scope // declaring scope + +Reference + identifier: Identifier + from: Scope // scope where the reference appears + resolved: Variable | null // null = global/undeclared + flag: ReferenceFlag // Read | Write | ReadWrite + writeExpr: Node | null // the rhs in an assignment + init: boolean // initializer write +``` + +**Key difference:** typescript-eslint is _Variable-centric_: each name gets a `Variable` object linking all its definition sites and use sites. Ours is _Identifier-centric_: each reference `Identifier` node maps to a `Scope`; we never build a `Variable` object grouping all uses of the same name. + +--- + +## Scope types created + +| Situation | Ours | typescript-eslint | +| ---------------------------------------------------------- | ----------------------------------------------------- | -------------------------------------------------------------- | +| Program / module | `Scope(undefined, isFunction=true)` (moduleScope) | `GlobalScope` + `ModuleScope` | +| `function f() {}` / `function() {}` / `() => {}` | `Scope(parent, isFunction=true)` | `FunctionScope` | +| Named function expression `(function f() {})` | function name added to the function's own scope | **`FunctionExpressionNameScope`** wrapping the `FunctionScope` | +| `class Foo {}` (declaration) | no extra scope | `ClassScope` with `Foo` defined inside | +| `(class Foo {})` (named expression) | `Scope(parent, isFunction=false)` with `Foo` declared | `ClassScope` with `Foo` defined inside | +| `(class {})` (anonymous expression) | no scope | `ClassScope` (still created) | +| `{ }` BlockStatement | `Scope(parent, isFunction=false)` | `BlockScope` | +| `for (…) {}` / `for…in` / `for…of` | `Scope(parent, isFunction=false)` | `ForScope` | +| `switch (…) {}` | `Scope(parent, isFunction=false)` | `SwitchScope` | +| `catch (e) {}` | `Scope(parent, isFunction=false)` | `CatchScope` | +| TypeScript-specific (enum, namespace, conditional type, …) | not supported | many extra scope types | + +### Notable divergence 1 — FunctionExpressionNameScope + +typescript-eslint inserts a **separate wrapper scope** for the name of a named function expression: + +``` +outer scope + └─ FunctionExpressionNameScope ← contains: f + └─ FunctionScope ← contains: params, var declarations +``` + +Source: [`FunctionExpressionNameScope.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/scope-manager/src/scope/FunctionExpressionNameScope.ts) + +Our implementation adds the function expression name directly into the function scope: + +``` +outer scope + └─ FunctionScope ← contains: f (the name), params, var declarations +``` + +Source: [scope.ts#L89-L91](../../../src/transforms/scope.ts#L89) + +**Practical effect:** In both cases, `f` is not visible in the outer scope. The self-recursive name is accessible inside the body. The difference only shows when introspecting the scope tree structure (e.g., ESLint rules that walk `scope.variables`). + +### Notable divergence 2 — ClassScope + +typescript-eslint creates a `ClassScope` for EVERY class (declaration and expression), always: + +```js +class Foo extends Base {} +``` + +``` +outer scope ← Foo defined here (for declarations) + └─ ClassScope ← Foo defined here again (inner self-reference for heritage + body) +``` + +Source: [`ClassVisitor.ts#L50-L63`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/scope-manager/src/referencer/ClassVisitor.ts#L50) + +Our implementation only creates a scope for **named class expressions** (the self-binding case), not for class declarations or anonymous class expressions: + +```js +const x = class Foo {} // ← creates Scope containing 'Foo' +class Foo {} // ← no extra scope; 'Foo' goes into current scope +``` + +Source: [scope.ts#L92-L100](../../../src/transforms/scope.ts#L92) + +**Practical effect:** References to `Foo` from within a class declaration's heritage (`extends Foo {}`) resolve to the outer binding in our implementation. typescript-eslint would resolve them to the inner `ClassScope` binding. For the RSC use case this distinction doesn't matter because we're looking for free variable bindings, not inner self-references. + +--- + +## Reference resolution strategy + +### Ours: post-walk deferred resolution + +1. Walk collects `{ id: Identifier, visitScope: Scope }` pairs without resolving. +2. After the walk (when all declarations are known), loop through raw refs and walk up the scope chain to find the declaring scope. + +**Why:** Avoids `var`/function hoisting bugs. A reference before its `var` declaration in the same function would incorrectly resolve to an outer scope if resolved eagerly. + +Source: [scope.ts#L51-L57](../../../src/transforms/scope.ts#L51) + +### typescript-eslint: close-time resolution + +1. During the walk each scope accumulates `leftToResolve: Reference[]`. +2. When a scope closes, it calls `close(scopeManager)` which tries to resolve each ref. +3. Unresolved refs are pushed to `through[]` and delegated to the upper scope via `delegateToUpperScope()`. + +Source: [`ScopeBase.ts#close`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/scope-manager/src/scope/ScopeBase.ts) + +Both strategies resolve at "scope exit" time (when all local declarations are visible), so they handle hoisting correctly. The difference is organizational: ours is a single post-walk pass; typescript-eslint resolves incrementally per scope. + +--- + +## Reference propagation + +### Ours: push to ALL ancestor scopes + +Every reference is added to `scopeToReferences` for its `visitScope` AND all ancestors up to the root. This makes it easy to ask "what identifiers are referenced inside scope X?" in O(1) at query time. + +Source: [scope.ts#L169-L173](../../../src/transforms/scope.ts#L169) + +### typescript-eslint: through[] chain + +Unresolved references bubble up via `through[]`. To find all refs accessible from a scope you'd need to walk `scope.through` recursively — there's no pre-aggregated list like our `scopeToReferences`. + +--- + +## `isReferenceIdentifier` / reference classification + +We implement this ourselves in [scope.ts#L202](../../../src/transforms/scope.ts#L202), modeled after Vite SSR's `isRefIdentifier`. typescript-eslint delegates this to `PatternVisitor` and `Referencer`, which drive the walk and explicitly call `scope.referenceValue()` / `scope.referenceType()` only at reference positions — they never need a negative filter because they control which nodes trigger a reference call. + +**Comment in our code:** `// TODO: review slop` — the positive-classifier approach is easier to audit but needs ongoing care as new node types are added. + +--- + +## What typescript-eslint provides that we don't + +1. **Read/Write flag on references** — knows if `x` is being read or written (or both). +2. **Definition kind** — `var` vs `let` vs `const` vs param vs import vs class name vs function name. +3. **`through[]`** — explicit "unresolved references" list per scope. +4. **TypeScript type-only references** — `ReferenceTypeFlag` distinguishes value vs type references. +5. **`ClassFieldInitializerScope` / `ClassStaticBlockScope`** — fine-grained scoping inside class bodies. +6. **`declaredVariables`** — `WeakMap` lets you go from any AST node back to what it declares. + +--- + +## What we have that typescript-eslint doesn't + +1. **`scopeToReferences` aggregation** — O(1) "all refs inside this scope" without recursion. +2. **Simpler model** — no Variable/Definition/Reference class hierarchy, just `Map`. +3. **Works on plain ESTree** — no TypeScript AST dependency. diff --git a/packages/plugin-rsc/docs/notes/scope-manager-research/vite-ssr.md b/packages/plugin-rsc/docs/notes/scope-manager-research/vite-ssr.md new file mode 100644 index 000000000..14381af7d --- /dev/null +++ b/packages/plugin-rsc/docs/notes/scope-manager-research/vite-ssr.md @@ -0,0 +1,135 @@ +# scope.ts vs Vite SSR transform: comparison + +**Our impl:** [src/transforms/scope.ts](../../../src/transforms/scope.ts) +**Prior art:** [github.com/vitejs/vite](https://github.com/vitejs/vite) — `packages/vite/src/node/ssr/ssrTransform.ts` (~L456–776) + +--- + +## Purpose + +The scope analysis in `ssrTransform.ts` is not a general-purpose scope library — it answers one specific question: which identifiers are free variables that reference an imported binding, so that the transform can rewrite them (e.g. `foo` → `__import_x__.foo`). This is a narrower goal than ours (`getBindVars` finds outer-scope closures for `use server` functions), but the underlying machinery is similar. + +--- + +## Data model + +### Ours + +``` +Scope (class) + declarations: Set + parent: Scope | undefined + isFunction: boolean + +ScopeTree + referenceToDeclaredScope: Map + scopeToReferences: Map + nodeScope: Map + moduleScope: Scope +``` + +### Vite SSR + +No `Scope` class — entirely ad-hoc with module-level data structures: + +```ts +const parentStack: ESTree.Node[] // DFS ancestor stack +const varKindStack: ESTree.VariableDeclaration['kind'][] // current var kind context +const scopeMap: WeakMap> // scope node → declared names +const identifiers: [id: ESTree.Identifier, stack: ESTree.Node[]][] // deferred reference list +``` + +`scopeMap` maps each scope-creating AST node directly to a `Set` of declared names — no `Scope` objects, no parent links. Scope hierarchy is reconstructed on demand by walking `parentStack`. + +--- + +## Scope types created (entries in `scopeMap`) + +| Situation | Vite SSR | Ours | +| ------------------------------------------------ | ----------------------------------------------- | ------------------------------------ | +| Program (module root) | `scopeMap.set(Program, ...)` | `moduleScope` | +| `function f() {}` / `function() {}` / `() => {}` | `scopeMap.set(fn, ...)` | `Scope(isFunction=true)` | +| Named fn expr `(function f() {})` | name added to the **function's own** scope node | same | +| `function f() {}` name | added to **parent** scope node | same | +| `class Foo {}` name | added to **parent** scope node | same | +| Named class expr `(class Foo {})` | name added to **class's own** scope node | `Scope(isFunction=false)` with `Foo` | +| `{ }` BlockStatement | `scopeMap.set(block, ...)` | `Scope(isFunction=false)` | +| `for` / `for…in` / `for…of` | `scopeMap.set(for, ...)` | `Scope(isFunction=false)` | +| `catch (e)` | `scopeMap.set(catch, ...)` | `Scope(isFunction=false)` | +| `class {}` static block | `scopeMap.set(staticBlock, ...)` | not handled | +| `switch` | not handled (no entry in `blockNodeTypeRE`) | `Scope(isFunction=false)` | + +Named class expression handling is the same as ours: the self-binding name is visible only inside the class. switch scopes diverge: Vite SSR skips them, we create one. + +--- + +## Resolution strategy + +### Vite SSR: two-phase, but eagerly filtered during walk + +**Phase 1 (DFS enter/leave):** Builds `scopeMap` with all declarations. References are identified by `isRefIdentifier()` and filtered by `isInScope()` during this pass — but only stored into `identifiers[]`, not resolved yet. + +**Phase 2 (sequential):** Processes `identifiers[]` in order. Re-checks `isInScope()` with the stored parent stack snapshot. + +```ts +identifiers.forEach(([node, stack]) => { + if (!isInScope(node.name, stack)) onIdentifier(node, stack[0], stack) +}) +``` + +`isInScope` walks the stored `parentStack` looking for a `scopeMap` entry that contains the name: + +```ts +function isInScope(name: string, parents: ESTree.Node[]) { + return parents.some((node) => scopeMap.get(node)?.has(name)) +} +``` + +Because phase 1 finishes before phase 2 begins, all declarations (including hoisted `var` and function declarations) are already in `scopeMap` when references are resolved. This is the same two-phase approach as ours, though expressed differently (we store `visitScope` reference; they store a `parentStack` snapshot). + +### Ours: post-walk, Identifier → declaring Scope + +We store `{ id: Identifier, visitScope: Scope }` and resolve by walking up the `Scope` parent chain. The outcome is the same but we produce a `Map` linking each ref to its declaring scope, whereas Vite SSR only produces a boolean "is this in scope or not". + +--- + +## `var` hoisting + +Vite SSR uses `varKindStack` to track whether the current declaration is `var`, then passes `isVar` to `findParentScope`: + +```ts +function findParentScope(parentStack, isVar = false) { + return parentStack.find(isVar ? isFunction : isBlock) +} +``` + +- `var` → finds nearest function scope (by `isFunction` regex match) +- `let`/`const` → finds nearest block scope (by `isBlock` regex match) + +Our implementation uses `getNearestFunctionScope()` for `var`, or stays at `current` for `let`/`const` — same logic, different expression. + +--- + +## Reference detection: `isRefIdentifier` + +Both implementations have an `isRefIdentifier` / `isReferenceIdentifier` function that filters out syntax-only identifier positions. Vite SSR's version is the direct inspiration for ours. Key differences: + +- Vite SSR pre-marks pattern nodes in a `WeakSet` during declaration handling, making pattern vs. expression distinction available at reference-check time without needing grandparent context. +- Our implementation uses the `parentStack` directly (grandparent lookups) instead of a pre-mark WeakSet. +- Vite SSR skips `ImportDeclaration` subtrees entirely with `this.skip()` so import specifier identifiers never reach the reference check. We handle them explicitly in `isReferenceIdentifier`. + +--- + +## What Vite SSR has that we don't + +- `StaticBlock` scope (class static initializers). +- Regex-based `isFunction` match catches generator and async variants (`GeneratorFunctionExpression`, `AsyncFunctionDeclaration`, etc.) generically without enumerating them. +- Pre-marked WeakSet for patterns — cleaner than grandparent-stack checks. + +## What we have that Vite SSR doesn't + +- `Scope` objects with parent links — enables walking the scope hierarchy without needing a `parentStack` snapshot. +- Per-`Identifier` → declaring `Scope` map — answers "where exactly does this ref resolve?" not just "is it in scope?". +- `scopeToReferences` aggregation — O(1) "all refs inside scope X". +- Named class expression scope (self-binding correctly isolated). +- `switch` scope. diff --git a/packages/plugin-rsc/package.json b/packages/plugin-rsc/package.json index 0364e8f5f..e6bc6d189 100644 --- a/packages/plugin-rsc/package.json +++ b/packages/plugin-rsc/package.json @@ -43,7 +43,6 @@ "es-module-lexer": "^2.0.0", "estree-walker": "^3.0.3", "magic-string": "^0.30.21", - "periscopic": "^4.0.2", "srvx": "^0.11.13", "strip-literal": "^3.1.0", "turbo-stream": "^3.2.0", diff --git a/packages/plugin-rsc/scripts/README.md b/packages/plugin-rsc/scripts/README.md new file mode 100644 index 000000000..cc9fe3108 --- /dev/null +++ b/packages/plugin-rsc/scripts/README.md @@ -0,0 +1,140 @@ +# Scripts + +## `import-typescript-eslint-scope-fixtures.ts` + +Regenerates the checked-in pre-transpiled JS fixture subtree at +`src/transforms/fixtures/scope/typescript-eslint/` from a local +`typescript-eslint` checkout. + +Source resolution order: + +```bash +1. --source /path/to/typescript-eslint/packages/scope-manager/tests/fixtures +2. TYPESCRIPT_ESLINT_SCOPE_FIXTURES_DIR +3. ../typescript-eslint/packages/scope-manager/tests/fixtures +``` + +Usage: + +```bash +cd packages/plugin-rsc +node ./scripts/import-typescript-eslint-scope-fixtures.ts +pnpm test -- scope.test.ts --update +``` + +Override the source directory when needed: + +```bash +cd packages/plugin-rsc +node ./scripts/import-typescript-eslint-scope-fixtures.ts \ + --source /path/to/typescript-eslint/packages/scope-manager/tests/fixtures +pnpm test -- scope.test.ts --update +``` + +Or set an environment variable: + +```bash +cd packages/plugin-rsc +TYPESCRIPT_ESLINT_SCOPE_FIXTURES_DIR=/path/to/typescript-eslint/packages/scope-manager/tests/fixtures \ + node ./scripts/import-typescript-eslint-scope-fixtures.ts +pnpm test -- scope.test.ts --update +``` + +Notes: + +- The checked-in subtree is JS-only for stable fixture inputs in this repo. +- The transpile step uses TypeScript `transpileModule` with + `experimentalDecorators: true` and `useDefineForClassFields: false`. +- `oxc` also mirrors this corpus in + `crates/oxc_semantic/tests/fixtures/typescript-eslint/`, but the canonical + upstream source is `typescript-eslint`. + +## `review-scope-fixtures.ts` + +Builds a Markdown review packet for scope fixtures. + +Usage: + +```bash +cd packages/plugin-rsc +node ./scripts/review-scope-fixtures.ts | code - +node ./scripts/review-scope-fixtures.ts shadowing import | code - +node ./scripts/review-scope-fixtures.ts var-hoisting --output /tmp/scope-review.md +``` + +## Review Workflow + +The imported `typescript-eslint` corpus is too large to review file-by-file in one pass. +The practical workflow is: + +1. Regenerate the pre-transpiled JS fixture subtree. + +```bash +cd packages/plugin-rsc +node ./scripts/import-typescript-eslint-scope-fixtures.ts +pnpm test -- scope.test.ts --update +``` + +2. Build review packets for targeted categories instead of the entire corpus. + +```bash +cd packages/plugin-rsc +node ./scripts/review-scope-fixtures.ts typescript-eslint/destructuring --output /tmp/destructuring.md +node ./scripts/review-scope-fixtures.ts typescript-eslint/import typescript-eslint/export --output /tmp/module-syntax.md +node ./scripts/review-scope-fixtures.ts typescript-eslint/class typescript-eslint/jsx --output /tmp/class-jsx.md +``` + +3. Sample by category, not exhaustively. + +Recommended categories: + +- `destructuring/` +- `import/` +- `export/` +- `catch/` +- `functions/` +- `class/` +- `jsx/` +- `decorators/` + +4. Review in parallel. + +When using subagents, split the audit by independent category groups and ask each +subagent to report only suspicious cases. A good split is: + +- `destructuring/`, `import/`, `export/`, `catch/` +- `class/`, `decorators/`, `jsx/` +- `functions/`, `global-resolution/`, `block/`, `call-expression/`, `member-expression/`, `new-expression/`, `implicit/` + +Each reviewer should compare: + +- original intent of the upstream fixture category +- transpiled JS fixture content +- generated `*.snap.json` + +and report only: + +- likely scope-analysis bugs +- fixtures whose TS -> JS lowering destroyed the original signal + +5. Prefer findings-driven follow-up. + +High-value follow-up is not “review every imported file”, but: + +- fix concrete scope-analysis bugs exposed by imported fixtures +- document or prune low-signal imported fixtures whose semantics are erased by transpilation + +## Current Caveats + +The import is intentionally JS-only, but some TS-specific fixtures lose value after +transpilation. Known weak-signal areas: + +- `decorators/`: helper injection like `__decorate` / `__param` can dominate the snapshot +- some `jsx/factory/` cases: JSX pragma semantics collapse to `_jsx(...)` runtime helper calls +- some `functions/arrow/` TS-only cases: type predicates, `asserts`, and type parameters can erase to identical JS + +Known likely real bug discovered during sampling: + +- `typescript-eslint/class/expression/self-reference-super.js` + `const A = class A extends A {}` appears to resolve `extends A` to the outer + `const A` instead of the inner class name diff --git a/packages/plugin-rsc/scripts/import-typescript-eslint-scope-fixtures.ts b/packages/plugin-rsc/scripts/import-typescript-eslint-scope-fixtures.ts new file mode 100644 index 000000000..2e2b01e0d --- /dev/null +++ b/packages/plugin-rsc/scripts/import-typescript-eslint-scope-fixtures.ts @@ -0,0 +1,132 @@ +import fs from 'node:fs' +import path from 'node:path' +import { parseArgs as parseNodeArgs } from 'node:util' +import ts from 'typescript' + +const scriptDir = path.dirname(new URL(import.meta.url).pathname) +const packageDir = path.resolve(scriptDir, '..') +const repoRoot = path.resolve(packageDir, '..', '..') +const siblingSourceHint = + '../typescript-eslint/packages/scope-manager/tests/fixtures' +const siblingSourceDir = path.resolve( + repoRoot, + '..', + 'typescript-eslint', + 'packages', + 'scope-manager', + 'tests', + 'fixtures', +) +const outputDir = path.join( + packageDir, + 'src/transforms/fixtures/scope/typescript-eslint', +) + +main().catch((error: unknown) => { + console.error(error) + process.exit(1) +}) + +async function main(): Promise { + const { values } = parseNodeArgs({ + args: process.argv.slice(2), + options: { + source: { + type: 'string', + short: 's', + }, + help: { + type: 'boolean', + short: 'h', + }, + }, + strict: true, + }) + + if (values.help) { + printHelp() + return + } + + const sourceDir = resolveSourceDir(values.source) + if (!sourceDir) { + throw new Error( + 'Fixture source directory is not configured.\n' + + 'Pass --source , set TYPESCRIPT_ESLINT_SCOPE_FIXTURES_DIR, or place a sibling\n' + + `typescript-eslint checkout at ${siblingSourceHint}`, + ) + } + + fs.rmSync(outputDir, { recursive: true, force: true }) + + const inputFiles = fs.globSync('**/*.{ts,tsx}', { cwd: sourceDir }).sort() + for (const relativePath of inputFiles) { + const inputPath = path.join(sourceDir, relativePath) + const outputPath = path.join( + outputDir, + relativePath.replace(/\.(ts|tsx)$/, '.js'), + ) + + fs.mkdirSync(path.dirname(outputPath), { recursive: true }) + + const input = fs.readFileSync(inputPath, 'utf8') + const result = ts.transpileModule(input, { + fileName: relativePath, + compilerOptions: { + target: ts.ScriptTarget.ESNext, + module: ts.ModuleKind.ESNext, + jsx: ts.JsxEmit.ReactJSX, + experimentalDecorators: true, + useDefineForClassFields: false, + }, + reportDiagnostics: true, + transformers: undefined, + }) + if (result.diagnostics?.length) { + const message = ts.formatDiagnosticsWithColorAndContext( + result.diagnostics, + { + getCanonicalFileName: (fileName) => fileName, + getCurrentDirectory: () => packageDir, + getNewLine: () => '\n', + }, + ) + throw new Error(`Failed to transpile fixture ${relativePath}\n${message}`) + } + fs.writeFileSync(outputPath, result.outputText) + } + + console.error( + `Imported ${inputFiles.length} fixture(s) from ${sourceDir} into ${outputDir}`, + ) +} + +function resolveSourceDir(cliSourceDir?: string): string | undefined { + const candidates = [ + cliSourceDir, + process.env['TYPESCRIPT_ESLINT_SCOPE_FIXTURES_DIR'], + siblingSourceDir, + ].filter((value): value is string => Boolean(value)) + + return candidates.find((candidate) => fs.existsSync(candidate)) +} + +function printHelp(): void { + console.log(`Usage: import-typescript-eslint-scope-fixtures [options] + +Transpile the local typescript-eslint scope-manager fixtures into checked-in JS +fixtures under src/transforms/fixtures/scope/typescript-eslint. + +Options: + -s, --source Source fixture directory + -h, --help Show this help + +Source resolution order: + 1. --source + 2. TYPESCRIPT_ESLINT_SCOPE_FIXTURES_DIR + 3. sibling checkout at ${siblingSourceHint} + +After import, regenerate snapshots with: + cd packages/plugin-rsc && pnpm test -- scope.test.ts --update +`) +} diff --git a/packages/plugin-rsc/scripts/review-scope-fixtures.ts b/packages/plugin-rsc/scripts/review-scope-fixtures.ts new file mode 100644 index 000000000..eb9f45b38 --- /dev/null +++ b/packages/plugin-rsc/scripts/review-scope-fixtures.ts @@ -0,0 +1,171 @@ +import fs from 'node:fs' +import path from 'node:path' +import { parseArgs as parseNodeArgs } from 'node:util' + +type Fixture = { + sourceFile: string + snapshotFile: string + relativePath: string + fixtureName: string + source: string + snapshot: string +} + +type FixtureEntry = Omit + +const scriptDir = path.dirname(new URL(import.meta.url).pathname) +const packageDir = path.resolve(scriptDir, '..') +const fixtureDir = path.join(packageDir, 'src/transforms/fixtures/scope') + +main() + +function main(): void { + const { values, positionals } = parseNodeArgs({ + args: process.argv.slice(2), + allowPositionals: true, + options: { + output: { + type: 'string', + short: 'o', + }, + help: { + type: 'boolean', + short: 'h', + }, + }, + strict: true, + }) + + if (values.help) { + printHelp() + process.exit(0) + } + + const filters = positionals + const output = values.output + const fixtures = collectFixtures(fixtureDir, filters) + + if (fixtures.length === 0) { + const detail = + filters.length === 0 + ? 'No fixtures found.' + : `No fixtures matched: ${filters.join(', ')}` + console.error(detail) + process.exit(1) + } + + const markdown = renderMarkdown(fixtures, filters) + + if (output) { + fs.writeFileSync(output, markdown) + console.error(`Wrote ${fixtures.length} fixture review(s) to ${output}`) + } else { + process.stdout.write(markdown) + } +} + +function printHelp(): void { + console.log(`Usage: review-scope-fixtures [filters...] [options] + +Build a Markdown review packet for scope fixtures. + +Positional arguments: + filters Substring filters matched against relative path or basename + +Options: + -o, --output Write to a specific file + -h, --help Show this help + +Examples: + pnpm review:scope-fixtures | code - + pnpm review:scope-fixtures shadowing import | code - + pnpm review:scope-fixtures var-hoisting --output /tmp/scope-review.md +`) +} + +function fail(message: string): never { + console.error(message) + process.exit(1) +} + +function collectFixtures(rootDir: string, filters: string[]): Fixture[] { + return fs + .globSync('**/*.js', { cwd: rootDir }) + .map((relativePath): FixtureEntry => { + const sourceFile = path.join(rootDir, relativePath) + return { + sourceFile, + snapshotFile: sourceFile + '.snap.json', + relativePath, + fixtureName: path.basename(sourceFile, '.js'), + } + }) + .filter((entry) => matchesFilters(entry, filters)) + .map((entry): Fixture => { + if (!fs.existsSync(entry.snapshotFile)) { + fail( + `Missing snapshot for ${entry.relativePath}: ${path.relative(packageDir, entry.snapshotFile)}`, + ) + } + + const source = fs.readFileSync(entry.sourceFile, 'utf8').trimEnd() + const snapshot = fs.readFileSync(entry.snapshotFile, 'utf8') + return { ...entry, source, snapshot } + }) + .sort((a, b) => a.relativePath.localeCompare(b.relativePath)) +} + +function matchesFilters(entry: FixtureEntry, filters: string[]): boolean { + if (filters.length === 0) { + return true + } + const haystacks = [entry.relativePath, entry.fixtureName].map((text) => + text.toLowerCase(), + ) + return filters.some((filter) => { + const needle = filter.toLowerCase() + return haystacks.some((text) => text.includes(needle)) + }) +} + +function renderMarkdown(fixtures: Fixture[], filters: string[]): string { + const lines = [ + '# Scope Fixture Review', + '', + `Generated: ${new Date().toISOString()}`, + '', + `Fixtures: ${fixtures.length}`, + ] + + if (filters.length > 0) { + lines.push(`Filters: ${filters.join(', ')}`) + } + + lines.push('', '## Contents', '') + + for (const fixture of fixtures) { + lines.push(`- \`${fixture.relativePath}\``) + } + + for (const fixture of fixtures) { + lines.push( + '', + `## ${fixture.relativePath}`, + '', + `Source: \`${path.relative(packageDir, fixture.sourceFile)}\``, + '', + '```js', + fixture.source, + '```', + '', + `Snapshot: \`${path.relative(packageDir, fixture.snapshotFile)}\``, + '', + '```json', + fixture.snapshot, + '```', + ) + } + + lines.push('') + return lines.join('\n') +} diff --git a/packages/plugin-rsc/src/transforms/cjs.ts b/packages/plugin-rsc/src/transforms/cjs.ts index 766ab13a0..20cfb1193 100644 --- a/packages/plugin-rsc/src/transforms/cjs.ts +++ b/packages/plugin-rsc/src/transforms/cjs.ts @@ -3,7 +3,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url' import type { Program, Node } from 'estree' import { walk } from 'estree-walker' import MagicString from 'magic-string' -import { analyze } from 'periscopic' +import { buildScopeTree } from './scope' // TODO: // replacing require("xxx") into import("xxx") affects Vite's resolution. @@ -33,7 +33,7 @@ export function transformCjsToEsm( options: { id: string }, ): { output: MagicString } { const output = new MagicString(code) - const analyzed = analyze(ast) + const scopeTree = buildScopeTree(ast) const parentNodes: Node[] = [] const hoistedCodes: string[] = [] @@ -58,8 +58,8 @@ export function transformCjsToEsm( isTopLevel = false } // skip locally declared `require` - const scope = analyzed.map.get(parent) - if (scope && scope.declarations.has('require')) { + const scope = scopeTree.nodeScope.get(parent) + if (scope?.declarations.has('require')) { return } } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js new file mode 100644 index 000000000..d387220d9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js @@ -0,0 +1,3 @@ +let a +const arr = [] +;[a] = arr diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js.snap.json new file mode 100644 index 000000000..b6f755dad --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/array-destructuring-assignment.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "a", + "arr" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + }, + { + "name": "arr", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js b/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js new file mode 100644 index 000000000..d738e537e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js @@ -0,0 +1,2 @@ +let a = 0 +a = 1 diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js.snap.json new file mode 100644 index 000000000..942fe4195 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/assign.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "a" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js b/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js new file mode 100644 index 000000000..2a2388386 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js @@ -0,0 +1,5 @@ +try { + throw 1 +} catch (e) { + console.log(e) +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js.snap.json new file mode 100644 index 000000000..a58d08a13 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/catch-param.js.snap.json @@ -0,0 +1,37 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + }, + { + "type": "CatchClause", + "declarations": [ + "e" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "console", + "declaredAt": null + }, + { + "name": "e", + "declaredAt": "Program > CatchClause" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js new file mode 100644 index 000000000..a6891e2be --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js @@ -0,0 +1 @@ +class Self extends Self {} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js.snap.json new file mode 100644 index 000000000..224b86467 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self-extends.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "Self" + ], + "references": [ + { + "name": "Self", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js new file mode 100644 index 000000000..f87144852 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js @@ -0,0 +1,5 @@ +class Self { + method() { + return Self + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js.snap.json new file mode 100644 index 000000000..c3c61c1f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl-self.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "Self" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Self", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js new file mode 100644 index 000000000..6d085d5f6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js @@ -0,0 +1,2 @@ +class Foo {} +const x = new Foo() diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js.snap.json new file mode 100644 index 000000000..798c85ce9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-decl.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "x" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js new file mode 100644 index 000000000..0ca0751ea --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js @@ -0,0 +1 @@ +const C = class Self extends Self {} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js.snap.json new file mode 100644 index 000000000..f9b631bae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self-extends.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "C" + ], + "references": [], + "children": [ + { + "type": "ClassExpression:Self", + "declarations": [ + "Self" + ], + "references": [ + { + "name": "Self", + "declaredAt": "Program > ClassExpression:Self" + } + ], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js new file mode 100644 index 000000000..4969ee030 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js @@ -0,0 +1,5 @@ +const C = class Self { + method() { + return Self + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js.snap.json new file mode 100644 index 000000000..d79f71944 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/class-expr-self.js.snap.json @@ -0,0 +1,36 @@ +{ + "type": "Program", + "declarations": [ + "C" + ], + "references": [], + "children": [ + { + "type": "ClassExpression:Self", + "declarations": [ + "Self" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Self", + "declaredAt": "Program > ClassExpression:Self" + } + ], + "children": [] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js b/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js new file mode 100644 index 000000000..9f3558711 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js @@ -0,0 +1,3 @@ +const key = 'k' +const obj = {} +const { [key]: val } = obj diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js.snap.json new file mode 100644 index 000000000..18cd0b69e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/computed-destructuring.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "key", + "obj", + "val" + ], + "references": [ + { + "name": "key", + "declaredAt": "Program" + }, + { + "name": "obj", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js b/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js new file mode 100644 index 000000000..b14c20a8a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js @@ -0,0 +1,3 @@ +function f({ a, b: [c, d] }, ...rest) { + return a + c + d + rest.length +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js.snap.json new file mode 100644 index 000000000..e34d07b8e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/destructured-params.js.snap.json @@ -0,0 +1,44 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [ + "a", + "c", + "d", + "rest" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:f" + }, + { + "name": "c", + "declaredAt": "Program > FunctionDeclaration:f" + }, + { + "name": "d", + "declaredAt": "Program > FunctionDeclaration:f" + }, + { + "name": "rest", + "declaredAt": "Program > FunctionDeclaration:f" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js new file mode 100644 index 000000000..6a6d64a19 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js @@ -0,0 +1,3 @@ +let bound +const obj = {} +;({ key: bound } = obj) diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js.snap.json new file mode 100644 index 000000000..1ead3baee --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/destructuring-assignment.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "bound", + "obj" + ], + "references": [ + { + "name": "bound", + "declaredAt": "Program" + }, + { + "name": "obj", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js new file mode 100644 index 000000000..f20f46ae2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js @@ -0,0 +1,2 @@ +const foo = 1 +export { foo as bar } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js.snap.json new file mode 100644 index 000000000..e4bbd8673 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/export-specifier.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [ + { + "name": "foo", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js new file mode 100644 index 000000000..8cf5ffb3c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js @@ -0,0 +1,4 @@ +function outer() { + foo() + function foo() {} +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js.snap.json new file mode 100644 index 000000000..667a14bc1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-decl-hoisting.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "foo" + ], + "references": [ + { + "name": "foo", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement" + } + ], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js new file mode 100644 index 000000000..deeaa2aec --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js @@ -0,0 +1,3 @@ +const f = function self() { + return self +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js.snap.json new file mode 100644 index 000000000..6e838ea96 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/fn-expr-name.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression:self", + "declarations": [ + "self" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "self", + "declaredAt": "Program > FunctionExpression:self" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js b/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js new file mode 100644 index 000000000..e9552628b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js @@ -0,0 +1 @@ +import.meta.env.DEV diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/import-meta.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js new file mode 100644 index 000000000..c006ab330 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js @@ -0,0 +1,2 @@ +import { foo as bar } from './mod' +bar() diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js.snap.json new file mode 100644 index 000000000..0dd886823 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/import-specifier.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "bar" + ], + "references": [ + { + "name": "bar", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/label.js b/packages/plugin-rsc/src/transforms/fixtures/scope/label.js new file mode 100644 index 000000000..16676f3b7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/label.js @@ -0,0 +1,6 @@ +outer: for (let i = 0; i < 3; i++) { + inner: for (let j = 0; j < 3; j++) { + if (j === 1) break outer + if (i === 1) continue inner + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/label.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/label.js.snap.json new file mode 100644 index 000000000..adc010776 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/label.js.snap.json @@ -0,0 +1,65 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "ForStatement", + "declarations": [ + "i" + ], + "references": [ + { + "name": "i", + "declaredAt": "Program > ForStatement" + }, + { + "name": "i", + "declaredAt": "Program > ForStatement" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "ForStatement", + "declarations": [ + "j" + ], + "references": [ + { + "name": "j", + "declaredAt": "Program > ForStatement > BlockStatement > ForStatement" + }, + { + "name": "j", + "declaredAt": "Program > ForStatement > BlockStatement > ForStatement" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "j", + "declaredAt": "Program > ForStatement > BlockStatement > ForStatement" + }, + { + "name": "i", + "declaredAt": "Program > ForStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js b/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js new file mode 100644 index 000000000..33ad80603 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js @@ -0,0 +1,7 @@ +function f() { + { + let x = 1 + const y = 2 + return x + y + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js.snap.json new file mode 100644 index 000000000..c0530f4ce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/let-const-block.js.snap.json @@ -0,0 +1,41 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "x", + "y" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program > FunctionDeclaration:f > BlockStatement > BlockStatement" + }, + { + "name": "y", + "declaredAt": "Program > FunctionDeclaration:f > BlockStatement > BlockStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js b/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js new file mode 100644 index 000000000..393ff43af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js @@ -0,0 +1,4 @@ +const obj = {} +const key = 'k' +obj.prop +obj[key] diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js.snap.json new file mode 100644 index 000000000..d58dbdba8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/member-expr.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "key", + "obj" + ], + "references": [ + { + "name": "obj", + "declaredAt": "Program" + }, + { + "name": "obj", + "declaredAt": "Program" + }, + { + "name": "key", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js b/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js new file mode 100644 index 000000000..c6a4818c2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js @@ -0,0 +1,5 @@ +const key = 'k' +class C { + method() {} + [key]() {} +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js.snap.json new file mode 100644 index 000000000..6d8c24331 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/method-definition.js.snap.json @@ -0,0 +1,41 @@ +{ + "type": "Program", + "declarations": [ + "C", + "key" + ], + "references": [ + { + "name": "key", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js b/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js new file mode 100644 index 000000000..e0cbdabfe --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js @@ -0,0 +1,4 @@ +const key = 'k' +const val = 1 +const obj = { key: val } +const { key: bound } = obj diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js.snap.json new file mode 100644 index 000000000..1c3ba48cd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/object-expr-vs-pattern.js.snap.json @@ -0,0 +1,20 @@ +{ + "type": "Program", + "declarations": [ + "bound", + "key", + "obj", + "val" + ], + "references": [ + { + "name": "val", + "declaredAt": "Program" + }, + { + "name": "obj", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js b/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js new file mode 100644 index 000000000..93d93b3be --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js @@ -0,0 +1,8 @@ +function outer() { + const y = 'outer' + function inner(x = y) { + var y = 'inner' + return x + } + return inner +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js.snap.json new file mode 100644 index 000000000..faf6896ad --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/param-default-var-hoisting.js.snap.json @@ -0,0 +1,57 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "inner", + "y" + ], + "references": [ + { + "name": "inner", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement" + } + ], + "children": [ + { + "type": "FunctionDeclaration:inner", + "declarations": [ + "x", + "y" + ], + "references": [ + { + "name": "y", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement > FunctionDeclaration:inner" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement > FunctionDeclaration:inner" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js b/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js new file mode 100644 index 000000000..371b92f7b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js @@ -0,0 +1,3 @@ +function f(a = ext, b = a) { + return b +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js.snap.json new file mode 100644 index 000000000..1421a7b34 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/param-defaults.js.snap.json @@ -0,0 +1,39 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [ + "a", + "b" + ], + "references": [ + { + "name": "ext", + "declaredAt": null + }, + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:f" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "b", + "declaredAt": "Program > FunctionDeclaration:f" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js b/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js new file mode 100644 index 000000000..e7b3bd13e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js @@ -0,0 +1,8 @@ +function outer() { + const x = 0 + function inner() { + const y = 1 + return x + y + } + return inner +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js.snap.json new file mode 100644 index 000000000..6d50446cf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/propagation.js.snap.json @@ -0,0 +1,55 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "inner", + "x" + ], + "references": [ + { + "name": "inner", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement" + } + ], + "children": [ + { + "type": "FunctionDeclaration:inner", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "y" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement" + }, + { + "name": "y", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement > FunctionDeclaration:inner > BlockStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js b/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js new file mode 100644 index 000000000..938e34ae5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js @@ -0,0 +1,4 @@ +const val = 1 +class C { + field = val +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js.snap.json new file mode 100644 index 000000000..5502e65c2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/property-definition.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "C", + "val" + ], + "references": [ + { + "name": "val", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js new file mode 100644 index 000000000..bfe3872a8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js @@ -0,0 +1,3 @@ +function f() { + console.log('hello') +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js.snap.json new file mode 100644 index 000000000..4cb25fec3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-global.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "console", + "declaredAt": null + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js new file mode 100644 index 000000000..149fda64c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js @@ -0,0 +1,6 @@ +function outer() { + const value = 0 + function inner() { + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js.snap.json new file mode 100644 index 000000000..987de0275 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/ref-outer-fn.js.snap.json @@ -0,0 +1,44 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "inner", + "value" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:inner", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "value", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js b/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js new file mode 100644 index 000000000..9a98b4c95 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js @@ -0,0 +1,9 @@ +function outer() { + const value = 0 + function action() { + if (true) { + const value = 1 + return value + } + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js.snap.json new file mode 100644 index 000000000..f87118215 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/shadowing-block.js.snap.json @@ -0,0 +1,53 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "action", + "value" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:action", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "value" + ], + "references": [ + { + "name": "value", + "declaredAt": "Program > FunctionDeclaration:outer > BlockStatement > FunctionDeclaration:action > BlockStatement > BlockStatement" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js new file mode 100644 index 000000000..ca02c6b27 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js @@ -0,0 +1,4 @@ +const a = 1; +{ + a; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js.snap.json new file mode 100644 index 000000000..450b3bbb7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/inherited-scope.js.snap.json @@ -0,0 +1,20 @@ +{ + "type": "Program", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js new file mode 100644 index 000000000..75974801a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js @@ -0,0 +1,6 @@ +{ + let i = 20; + let j = 1; + i; +} +j; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js.snap.json new file mode 100644 index 000000000..6570e7248 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/block/scope.js.snap.json @@ -0,0 +1,26 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "j", + "declaredAt": null + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "i", + "j" + ], + "references": [ + { + "name": "i", + "declaredAt": "Program > BlockStatement" + } + ], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js new file mode 100644 index 000000000..6aa85a9a3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js @@ -0,0 +1,4 @@ +const foo = () => { }; +const a = 1; +foo(a); +foo?.(a); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js.snap.json new file mode 100644 index 000000000..136b590a1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/call-expression.js.snap.json @@ -0,0 +1,40 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [ + { + "name": "foo", + "declaredAt": "Program" + }, + { + "name": "a", + "declaredAt": "Program" + }, + { + "name": "foo", + "declaredAt": "Program" + }, + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js new file mode 100644 index 000000000..a280f9a5c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js @@ -0,0 +1 @@ +foo(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js.snap.json new file mode 100644 index 000000000..f7dad41f9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters1.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js new file mode 100644 index 000000000..9d75ca758 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js @@ -0,0 +1,2 @@ +const T = 1; +foo(); // should not resolve to value diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js.snap.json new file mode 100644 index 000000000..0a6aac5fe --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/call-expression/type-parameters2.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [ + { + "name": "foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js new file mode 100644 index 000000000..75d6a233e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js @@ -0,0 +1,3 @@ +try { +} +catch ([a, [b], c = 1, ...d]) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js.snap.json new file mode 100644 index 000000000..dcacff70c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-array.js.snap.json @@ -0,0 +1,31 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + }, + { + "type": "CatchClause", + "declarations": [ + "a", + "b", + "c", + "d" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js new file mode 100644 index 000000000..2a95b184e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js @@ -0,0 +1,3 @@ +try { +} +catch ({ a, x: b, y: { c }, d = 1, ...e }) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js.snap.json new file mode 100644 index 000000000..37ffa1326 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/destructuring-object.js.snap.json @@ -0,0 +1,32 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + }, + { + "type": "CatchClause", + "declarations": [ + "a", + "b", + "c", + "d", + "e" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js new file mode 100644 index 000000000..923759c18 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js @@ -0,0 +1,6 @@ +const a = 1; +try { +} +catch (e) { + a; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js.snap.json new file mode 100644 index 000000000..e9970c177 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/inherited-scope.js.snap.json @@ -0,0 +1,35 @@ +{ + "type": "Program", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + }, + { + "type": "CatchClause", + "declarations": [ + "e" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js new file mode 100644 index 000000000..2874fcb17 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js @@ -0,0 +1,8 @@ +try { +} +catch (e) { + e; + let a = 1; +} +const unresolved = e; +const dontReference2 = a; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js.snap.json new file mode 100644 index 000000000..9c16ce970 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/catch/scope.js.snap.json @@ -0,0 +1,47 @@ +{ + "type": "Program", + "declarations": [ + "dontReference2", + "unresolved" + ], + "references": [ + { + "name": "e", + "declaredAt": null + }, + { + "name": "a", + "declaredAt": null + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + }, + { + "type": "CatchClause", + "declarations": [ + "e" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [ + { + "name": "e", + "declaredAt": "Program > CatchClause" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js new file mode 100644 index 000000000..f230fa0f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js @@ -0,0 +1,2 @@ +class Foo { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js.snap.json new file mode 100644 index 000000000..bae86bc58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-accessor-property.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js new file mode 100644 index 000000000..f230fa0f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js @@ -0,0 +1,2 @@ +class Foo { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js.snap.json new file mode 100644 index 000000000..bae86bc58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract-property.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js new file mode 100644 index 000000000..2e2439c32 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js @@ -0,0 +1,2 @@ +class A { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js.snap.json new file mode 100644 index 000000000..91d17a9e2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/abstract.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js new file mode 100644 index 000000000..2e2439c32 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js @@ -0,0 +1,2 @@ +class A { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js.snap.json new file mode 100644 index 000000000..91d17a9e2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property-type-annotation.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js new file mode 100644 index 000000000..1b7a70c6b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js @@ -0,0 +1,8 @@ +const x = 1; +class A { + constructor() { + this.prop1 = 1; + this.prop2 = x; + } +} +const unresolved = prop1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js.snap.json new file mode 100644 index 000000000..9f7173c9b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/accessor-property.js.snap.json @@ -0,0 +1,34 @@ +{ + "type": "Program", + "declarations": [ + "A", + "unresolved", + "x" + ], + "references": [ + { + "name": "prop1", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js new file mode 100644 index 000000000..420e53dbe --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js @@ -0,0 +1,9 @@ +var _a; +const outer1 = 'a'; +const outer2 = 'b'; +class A { + constructor() { + this[_a] = 1; + } + [(_a = outer1, outer2)]() { } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js.snap.json new file mode 100644 index 000000000..c66443fdb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/computed-member.js.snap.json @@ -0,0 +1,56 @@ +{ + "type": "Program", + "declarations": [ + "A", + "_a", + "outer1", + "outer2" + ], + "references": [ + { + "name": "_a", + "declaredAt": "Program" + }, + { + "name": "outer1", + "declaredAt": "Program" + }, + { + "name": "outer2", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "_a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js new file mode 100644 index 000000000..1d2ce7774 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js @@ -0,0 +1,4 @@ +class A { +} +class B extends A { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js.snap.json new file mode 100644 index 000000000..dfd30670f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends-generic.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "A", + "B" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js new file mode 100644 index 000000000..1d2ce7774 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js @@ -0,0 +1,4 @@ +class A { +} +class B extends A { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js.snap.json new file mode 100644 index 000000000..dfd30670f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/extends.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "A", + "B" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js new file mode 100644 index 000000000..cc0572404 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js @@ -0,0 +1,2 @@ +class Foo extends Bar { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js.snap.json new file mode 100644 index 000000000..cbaf1f1ee --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-extends.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Bar", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js new file mode 100644 index 000000000..f230fa0f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js @@ -0,0 +1,2 @@ +class Foo { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js.snap.json new file mode 100644 index 000000000..bae86bc58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic-ref-implements.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js new file mode 100644 index 000000000..f230fa0f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js @@ -0,0 +1,2 @@ +class Foo { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js.snap.json new file mode 100644 index 000000000..bae86bc58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/generic.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js new file mode 100644 index 000000000..7d95eb649 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js @@ -0,0 +1,2 @@ +class B { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js.snap.json new file mode 100644 index 000000000..cf5fb0075 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements-generic.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "B" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js new file mode 100644 index 000000000..7d95eb649 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js @@ -0,0 +1,2 @@ +class B { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js.snap.json new file mode 100644 index 000000000..cf5fb0075 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/implements.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "B" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js new file mode 100644 index 000000000..f230fa0f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js @@ -0,0 +1,2 @@ +class Foo { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js.snap.json new file mode 100644 index 000000000..bae86bc58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/index-signature.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js new file mode 100644 index 000000000..aee6cabc5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js @@ -0,0 +1,10 @@ +// https://github.com/typescript-eslint/typescript-eslint/issues/2941 +class A { + constructor(printName) { + this.printName = printName; + } + openPort(printerName = this.printerName) { + this.tscOcx.ActiveXopenport(printerName); + return this; + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js.snap.json new file mode 100644 index 000000000..4b5e695be --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method-param-default.js.snap.json @@ -0,0 +1,49 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "printName" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "printName", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [ + "printerName" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "printerName", + "declaredAt": "Program > FunctionExpression[2]" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js new file mode 100644 index 000000000..3b6da42b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js @@ -0,0 +1,7 @@ +class A { + method(a, [b], { c }, d = 1, e = a, f) { + a; + } +} +const unresolved1 = f; +const unresolved2 = method; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js.snap.json new file mode 100644 index 000000000..63dd94893 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/method.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "A", + "unresolved1", + "unresolved2" + ], + "references": [ + { + "name": "f", + "declaredAt": null + }, + { + "name": "method", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js new file mode 100644 index 000000000..65cd49d00 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js @@ -0,0 +1,3 @@ +class A { +} +new A(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js.snap.json new file mode 100644 index 000000000..cbeafe6bf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/new.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js new file mode 100644 index 000000000..6a32e003d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js @@ -0,0 +1,13 @@ +const outer = 1; +class A { + constructor(a, b = 1, c = a, d = outer, e, f) { + this.a = a; + this.b = b; + this.c = c; + this.d = d; + this.e = e; + this.f = f; + a; + } +} +const unresovled = e; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js.snap.json new file mode 100644 index 000000000..49b4909af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/parameter-properties.js.snap.json @@ -0,0 +1,74 @@ +{ + "type": "Program", + "declarations": [ + "A", + "outer", + "unresovled" + ], + "references": [ + { + "name": "e", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "outer", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "b", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "e", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "f", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js new file mode 100644 index 000000000..4f477efef --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js @@ -0,0 +1,6 @@ +class Foo { + #bar; + constructor() { + this.#bar = 1; + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js.snap.json new file mode 100644 index 000000000..08cba24c1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/private-identifier.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js new file mode 100644 index 000000000..2e2439c32 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js @@ -0,0 +1,2 @@ +class A { +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js.snap.json new file mode 100644 index 000000000..91d17a9e2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties-type-annotation.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js new file mode 100644 index 000000000..1b7a70c6b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js @@ -0,0 +1,8 @@ +const x = 1; +class A { + constructor() { + this.prop1 = 1; + this.prop2 = x; + } +} +const unresolved = prop1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js.snap.json new file mode 100644 index 000000000..9f7173c9b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/properties.js.snap.json @@ -0,0 +1,34 @@ +{ + "type": "Program", + "declarations": [ + "A", + "unresolved", + "x" + ], + "references": [ + { + "name": "prop1", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js new file mode 100644 index 000000000..b043d4bfd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js @@ -0,0 +1,3 @@ +class A { + static { } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js.snap.json new file mode 100644 index 000000000..91d17a9e2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-block.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js new file mode 100644 index 000000000..2cb63cbad --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js @@ -0,0 +1,6 @@ +function f() { } +class A { + static { + f(); + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js.snap.json new file mode 100644 index 000000000..44f702b57 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-external-ref.js.snap.json @@ -0,0 +1,28 @@ +{ + "type": "Program", + "declarations": [ + "A", + "f" + ], + "references": [ + { + "name": "f", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js new file mode 100644 index 000000000..edcc44834 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js @@ -0,0 +1,8 @@ +// https://github.com/typescript-eslint/typescript-eslint/issues/5577 +function f() { } +class A { + static { } + constructor() { + f(); + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js.snap.json new file mode 100644 index 000000000..f405ff24d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/static-with-constructor.js.snap.json @@ -0,0 +1,41 @@ +{ + "type": "Program", + "declarations": [ + "A", + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "f", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js new file mode 100644 index 000000000..73bf9cca3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js @@ -0,0 +1,3 @@ +class A { +} +const v = A; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js.snap.json new file mode 100644 index 000000000..0bc7e6d2c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/declaration/type-reference.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "A", + "v" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js new file mode 100644 index 000000000..e0a74f88c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js @@ -0,0 +1,9 @@ +var _a; +const outer1 = 'a'; +const outer2 = 'b'; +const A = class { + constructor() { + this[_a] = 1; + } + [(_a = outer1, outer2)]() { } +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js.snap.json new file mode 100644 index 000000000..c66443fdb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/computed-member.js.snap.json @@ -0,0 +1,56 @@ +{ + "type": "Program", + "declarations": [ + "A", + "_a", + "outer1", + "outer2" + ], + "references": [ + { + "name": "_a", + "declaredAt": "Program" + }, + { + "name": "outer1", + "declaredAt": "Program" + }, + { + "name": "outer2", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "_a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js new file mode 100644 index 000000000..1ac6ac049 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js @@ -0,0 +1,4 @@ +class A { +} +const B = class extends A { +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js.snap.json new file mode 100644 index 000000000..dfd30670f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/extends.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "A", + "B" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js new file mode 100644 index 000000000..868cd46dc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js @@ -0,0 +1,7 @@ +const A = class { + method(a, [b], { c }, d = 1, e = a, f) { + a; + } +}; +const unresolved1 = f; +const unresolved2 = method; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js.snap.json new file mode 100644 index 000000000..63dd94893 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/method.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "A", + "unresolved1", + "unresolved2" + ], + "references": [ + { + "name": "f", + "declaredAt": null + }, + { + "name": "method", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js new file mode 100644 index 000000000..a1761bd1d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js @@ -0,0 +1,3 @@ +const A = class { +}; +new A(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js.snap.json new file mode 100644 index 000000000..cbeafe6bf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/new.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js new file mode 100644 index 000000000..1824fbcad --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js @@ -0,0 +1,13 @@ +const outer = 1; +const A = class { + constructor(a, b = 1, c = a, d = outer, e, f) { + this.a = a; + this.b = b; + this.c = c; + this.d = d; + this.e = e; + this.f = f; + a; + } +}; +const unresovled = e; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js.snap.json new file mode 100644 index 000000000..49b4909af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/parameter-properties.js.snap.json @@ -0,0 +1,74 @@ +{ + "type": "Program", + "declarations": [ + "A", + "outer", + "unresovled" + ], + "references": [ + { + "name": "e", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "outer", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "b", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "e", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "f", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js new file mode 100644 index 000000000..c61c3ca21 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js @@ -0,0 +1,6 @@ +const Foo = class { + #bar; + constructor() { + this.#bar = 1; + } +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js.snap.json new file mode 100644 index 000000000..08cba24c1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/private-identifier.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js new file mode 100644 index 000000000..b63a8dd0f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js @@ -0,0 +1,8 @@ +const x = 1; +const A = class { + constructor() { + this.prop1 = 1; + this.prop2 = x; + } +}; +const unresolved = prop; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js.snap.json new file mode 100644 index 000000000..047501b5c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/properties.js.snap.json @@ -0,0 +1,34 @@ +{ + "type": "Program", + "declarations": [ + "A", + "unresolved", + "x" + ], + "references": [ + { + "name": "prop", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js new file mode 100644 index 000000000..a83e4f7b1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js @@ -0,0 +1,4 @@ +const A = class A +// this A references the class A, not the variable A + extends A { +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js.snap.json new file mode 100644 index 000000000..57f9830f4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/class/expression/self-reference-super.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "A" + ], + "references": [], + "children": [ + { + "type": "ClassExpression:A", + "declarations": [ + "A" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program > ClassExpression:A" + } + ], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js new file mode 100644 index 000000000..5d58913da --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js @@ -0,0 +1,19 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +function decorator() { } +class Foo { + get foo() { + return 1; + } + set bar(value) { } +} +__decorate([ + decorator +], Foo.prototype, "foo", null); +__decorate([ + decorator +], Foo.prototype, "bar", null); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js.snap.json new file mode 100644 index 000000000..ad86862e5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/accessor.js.snap.json @@ -0,0 +1,280 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "decorator" + ], + "references": [ + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[3]", + "declarations": [ + "value" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js new file mode 100644 index 000000000..360172f93 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js @@ -0,0 +1,16 @@ +// https://github.com/typescript-eslint/typescript-eslint/issues/2942 +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +let Foo = class Foo { +}; +Foo = __decorate([ + deco({ + components: { + val: true, + }, + }) +], Foo); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js.snap.json new file mode 100644 index 000000000..4f8fcdde7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-deco-with-object-param.js.snap.json @@ -0,0 +1,238 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "deco", + "declaredAt": null + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "ClassExpression:Foo", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js new file mode 100644 index 000000000..91884a9b1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js @@ -0,0 +1,12 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +function decorator() { } +class Foo { +} +__decorate([ + decorator +], Foo.prototype, "foo", void 0); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js.snap.json new file mode 100644 index 000000000..aa0f85797 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class-property.js.snap.json @@ -0,0 +1,240 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "decorator" + ], + "references": [ + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js new file mode 100644 index 000000000..5756f1ef2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js @@ -0,0 +1,12 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +function decorator() { } +let Foo = class Foo { +}; +Foo = __decorate([ + decorator +], Foo); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js.snap.json new file mode 100644 index 000000000..0a856dbbd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/class.js.snap.json @@ -0,0 +1,252 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "decorator" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "ClassExpression:Foo", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js new file mode 100644 index 000000000..366d4f624 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js @@ -0,0 +1,13 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +function decorator() { } +class Foo { + foo() { } +} +__decorate([ + decorator +], Foo.prototype, "foo", null); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js.snap.json new file mode 100644 index 000000000..8e0bb9d07 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/method.js.snap.json @@ -0,0 +1,253 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "decorator" + ], + "references": [ + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js new file mode 100644 index 000000000..d0d097a09 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js @@ -0,0 +1,20 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +}; +function decorator() { } +let Foo = class Foo { + constructor(a, b = 1) { + this.a = a; + this.b = b; + } +}; +Foo = __decorate([ + __param(0, decorator), + __param(1, decorator) +], Foo); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js.snap.json new file mode 100644 index 000000000..5e5399926 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter-property.js.snap.json @@ -0,0 +1,341 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "__param", + "decorator" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [ + "decorator", + "paramIndex" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "key", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "decorator", + "declaredAt": "Program > FunctionExpression[2]" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression[2] > BlockStatement > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression[2] > BlockStatement > FunctionExpression" + }, + { + "name": "paramIndex", + "declaredAt": "Program > FunctionExpression[2]" + } + ], + "children": [] + } + ] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "ClassExpression:Foo", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > ClassExpression:Foo > FunctionExpression" + }, + { + "name": "b", + "declaredAt": "Program > ClassExpression:Foo > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js new file mode 100644 index 000000000..22a580ff7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js @@ -0,0 +1,21 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __param = (this && this.__param) || function (paramIndex, decorator) { + return function (target, key) { decorator(target, key, paramIndex); } +}; +function decorator() { } +class A { + foo(a, [b], { c }, d = 1, decorator, decorator) { } +} +__decorate([ + __param(0, decorator), + __param(1, decorator), + __param(2, decorator), + __param(3, decorator), + __param(4, decorator), + __param(5, d) +], A.prototype, "foo", null); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js.snap.json new file mode 100644 index 000000000..31e6649a4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/parameter.js.snap.json @@ -0,0 +1,354 @@ +{ + "type": "Program", + "declarations": [ + "A", + "__decorate", + "__param", + "decorator" + ], + "references": [ + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "__param", + "declaredAt": "Program" + }, + { + "name": "d", + "declaredAt": null + }, + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [ + "decorator", + "paramIndex" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "key", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "decorator", + "declaredAt": "Program > FunctionExpression[2]" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression[2] > BlockStatement > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression[2] > BlockStatement > FunctionExpression" + }, + { + "name": "paramIndex", + "declaredAt": "Program > FunctionExpression[2]" + } + ], + "children": [] + } + ] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression[3]", + "declarations": [ + "a", + "b", + "c", + "d", + "decorator" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js new file mode 100644 index 000000000..59f131be3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js @@ -0,0 +1,13 @@ +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +function decorator() { } +let Foo = class Foo { + bar(baz) { } +}; +Foo = __decorate([ + decorator +], Foo); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js.snap.json new file mode 100644 index 000000000..c55a60d99 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/decorators/typeof-this.js.snap.json @@ -0,0 +1,268 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "__decorate", + "decorator" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "__decorate", + "declaredAt": "Program" + }, + { + "name": "decorator", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "c", + "d", + "decorators", + "desc", + "i", + "key", + "r", + "target" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arguments", + "declaredAt": null + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Reflect", + "declaredAt": null + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "desc", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Object", + "declaredAt": null + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "ForStatement", + "declarations": [], + "references": [ + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "decorators", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "i", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "c", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "d", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "target", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "key", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "r", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionDeclaration:decorator", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "ClassExpression:Foo", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "baz" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js new file mode 100644 index 000000000..a0fb37e1e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js @@ -0,0 +1,3 @@ +const obj = {}; +let b, c; +[obj.a, b, [c]] = []; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js.snap.json new file mode 100644 index 000000000..ba9465be5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array-assignment.js.snap.json @@ -0,0 +1,23 @@ +{ + "type": "Program", + "declarations": [ + "b", + "c", + "obj" + ], + "references": [ + { + "name": "obj", + "declaredAt": "Program" + }, + { + "name": "b", + "declaredAt": "Program" + }, + { + "name": "c", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js new file mode 100644 index 000000000..86f9cf690 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js @@ -0,0 +1 @@ +const [a, b, c, d = 1, [e], [f] = g, ...rest] = []; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js.snap.json new file mode 100644 index 000000000..f8818040b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/array.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f", + "rest" + ], + "references": [ + { + "name": "g", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js new file mode 100644 index 000000000..dbfbfe75f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js @@ -0,0 +1,6 @@ +const obj = {}; +({ + shorthand, + key: value, + hello: { world: obj.a }, +} = object); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js.snap.json new file mode 100644 index 000000000..ba166ae60 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object-assignment.js.snap.json @@ -0,0 +1,25 @@ +{ + "type": "Program", + "declarations": [ + "obj" + ], + "references": [ + { + "name": "shorthand", + "declaredAt": null + }, + { + "name": "value", + "declaredAt": null + }, + { + "name": "obj", + "declaredAt": "Program" + }, + { + "name": "object", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js new file mode 100644 index 000000000..4e56dc72c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js @@ -0,0 +1 @@ +const { shorthand, key: value, hello: { world }, array: [a, b, c, d], } = object; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js.snap.json new file mode 100644 index 000000000..8578eb6ba --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/destructuring/object.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "a", + "b", + "c", + "d", + "shorthand", + "value", + "world" + ], + "references": [ + { + "name": "object", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js new file mode 100644 index 000000000..43a75cae0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js @@ -0,0 +1,3 @@ +//// @sourceType = module +export * from 'foo'; +export * as bar from 'foo'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js.snap.json new file mode 100644 index 000000000..c2bf84840 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/all.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "bar", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js new file mode 100644 index 000000000..c5b2574d5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const T = 1; // unreferenced +export default T; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js.snap.json new file mode 100644 index 000000000..31b6fb6bf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default-type.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [ + { + "name": "T", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js new file mode 100644 index 000000000..8bf196ed6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export default function f() { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js.snap.json new file mode 100644 index 000000000..3c616f0ce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default1.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js new file mode 100644 index 000000000..2c21f0716 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const a = 1; +export default a; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js.snap.json new file mode 100644 index 000000000..942fe4195 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default2.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "a" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js new file mode 100644 index 000000000..821dbfd12 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export default 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default3.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js new file mode 100644 index 000000000..9a030f478 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export default function () { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js.snap.json new file mode 100644 index 000000000..ced604c0c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/default4.js.snap.json @@ -0,0 +1,20 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "FunctionDeclaration", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js new file mode 100644 index 000000000..49c03efc1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const x = 1; +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals1.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js @@ -0,0 +1 @@ +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals3-type.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js @@ -0,0 +1 @@ +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/equals4-type.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js new file mode 100644 index 000000000..130c4d668 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js @@ -0,0 +1,2 @@ +const T = 1; +export { T }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js.snap.json new file mode 100644 index 000000000..31b6fb6bf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-dual.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [ + { + "name": "T", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js new file mode 100644 index 000000000..a01e7aed4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export { x } from 'foo'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js.snap.json new file mode 100644 index 000000000..393f571ea --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source1.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js new file mode 100644 index 000000000..913fb9e40 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export { v as x } from 'foo'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js.snap.json new file mode 100644 index 000000000..df2af3e13 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-source2.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "v", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named-type1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js new file mode 100644 index 000000000..34e29b11a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export const x = 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named1.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2-type.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js new file mode 100644 index 000000000..4f8a5492f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const a = 1; +export { a }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js.snap.json new file mode 100644 index 000000000..942fe4195 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named2.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "a" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3-type.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js new file mode 100644 index 000000000..1fea45890 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const v = 1; +export { v as x }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js.snap.json new file mode 100644 index 000000000..20cab1f82 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/named3.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "v" + ], + "references": [ + { + "name": "v", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js new file mode 100644 index 000000000..34ff9b484 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const T = 1; // unreferenced +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js.snap.json new file mode 100644 index 000000000..4a4b769d5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type-inline.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js new file mode 100644 index 000000000..34ff9b484 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const T = 1; // unreferenced +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js.snap.json new file mode 100644 index 000000000..4a4b769d5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/export/type.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js new file mode 100644 index 000000000..c1b437731 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js @@ -0,0 +1,5 @@ +let a; +// the default param value is resolved to the outer scope +let foo = (b = a) => { + let a; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js.snap.json new file mode 100644 index 000000000..8a03fe757 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.js.snap.json @@ -0,0 +1,32 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js new file mode 100644 index 000000000..67fd9a51c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js @@ -0,0 +1,2 @@ +const a = 0; +let foo = (b = a) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js.snap.json new file mode 100644 index 000000000..41a73c0bb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-const.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js new file mode 100644 index 000000000..c91b75870 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js @@ -0,0 +1,2 @@ +let a; +let foo = (b = a) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js.snap.json new file mode 100644 index 000000000..41a73c0bb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-let.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js new file mode 100644 index 000000000..aeefa10b6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js @@ -0,0 +1,6 @@ +let a; +let foo = (b = function () { + a; +}) => { + let a; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js.snap.json new file mode 100644 index 000000000..8122a466f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.js.snap.json @@ -0,0 +1,45 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js new file mode 100644 index 000000000..ab231bd70 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js @@ -0,0 +1,4 @@ +let a; +let foo = (b = function () { + return a; +}) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js.snap.json new file mode 100644 index 000000000..0879f3409 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-nested.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js new file mode 100644 index 000000000..50290bd03 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js @@ -0,0 +1,3 @@ +let a; +// the default param value is resolved to the parameter +let foo = (b = a, a) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js.snap.json new file mode 100644 index 000000000..f80cc3308 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.js.snap.json @@ -0,0 +1,31 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "a", + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > ArrowFunction" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js new file mode 100644 index 000000000..10cf659ea --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js @@ -0,0 +1,2 @@ +let a; +let foo = (b = a.c) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js.snap.json new file mode 100644 index 000000000..41a73c0bb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/readable-ref-partial.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js new file mode 100644 index 000000000..1d821a01b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js @@ -0,0 +1 @@ +let foo = (a, b = 0) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js.snap.json new file mode 100644 index 000000000..711ef93dd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/default-params/writable-ref.js.snap.json @@ -0,0 +1,25 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "a", + "b" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js new file mode 100644 index 000000000..4cc80bdba --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js @@ -0,0 +1,4 @@ +const parentScoped = 1; +() => { + parentScoped + 1; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js.snap.json new file mode 100644 index 000000000..1ee5c56cd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/inherited-scope.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "parentScoped" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "parentScoped", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js new file mode 100644 index 000000000..d24dce0d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js @@ -0,0 +1 @@ +a => a; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js.snap.json new file mode 100644 index 000000000..e48c6db43 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/no-body.js.snap.json @@ -0,0 +1,20 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "a" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > ArrowFunction" + } + ], + "children": [] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js new file mode 100644 index 000000000..db4a4b58f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js @@ -0,0 +1,5 @@ +const outer = 1; +(a, [b], { c }, d = 1, e = a, f = outer, g) => { + a; +}; +const unresolved = g; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js.snap.json new file mode 100644 index 000000000..a82edf5e1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/params.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "outer", + "unresolved" + ], + "references": [ + { + "name": "g", + "declaredAt": null + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f", + "g" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > ArrowFunction" + }, + { + "name": "outer", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > ArrowFunction" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js new file mode 100644 index 000000000..b3ac01ad0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js @@ -0,0 +1,6 @@ +const arrow = () => { + let i = 0; + var j = 20; + i; +}; +const unresolved = j; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js.snap.json new file mode 100644 index 000000000..7c73aa937 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/scope.js.snap.json @@ -0,0 +1,37 @@ +{ + "type": "Program", + "declarations": [ + "arrow", + "unresolved" + ], + "references": [ + { + "name": "j", + "declaredAt": null + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "j" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "i" + ], + "references": [ + { + "name": "i", + "declaredAt": "Program > ArrowFunction > BlockStatement" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js new file mode 100644 index 000000000..845f6c130 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js @@ -0,0 +1,3 @@ +const foo = () => { + let x; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js.snap.json new file mode 100644 index 000000000..f36ba72b7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/body-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "x" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js new file mode 100644 index 000000000..e71d31fff --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js @@ -0,0 +1 @@ +const foo = (a) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js.snap.json new file mode 100644 index 000000000..bd0bb3dba --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/param-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js new file mode 100644 index 000000000..711242b2e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js @@ -0,0 +1 @@ +const foo = () => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js.snap.json new file mode 100644 index 000000000..71937a22c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/return-value-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js new file mode 100644 index 000000000..711242b2e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js @@ -0,0 +1 @@ +const foo = () => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js.snap.json new file mode 100644 index 000000000..71937a22c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-param-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js new file mode 100644 index 000000000..711242b2e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js @@ -0,0 +1 @@ +const foo = () => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js.snap.json new file mode 100644 index 000000000..71937a22c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js new file mode 100644 index 000000000..ed880c59f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js @@ -0,0 +1 @@ +const foo = (arg) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js.snap.json new file mode 100644 index 000000000..eee1ad421 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts1.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js new file mode 100644 index 000000000..ed880c59f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js @@ -0,0 +1 @@ +const foo = (arg) => { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js.snap.json new file mode 100644 index 000000000..eee1ad421 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate-asserts2.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js new file mode 100644 index 000000000..e40a5bb4e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js @@ -0,0 +1,3 @@ +const foo = (arg) => { + return typeof arg === 'string'; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js.snap.json new file mode 100644 index 000000000..a337d1442 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate1.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > ArrowFunction" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js new file mode 100644 index 000000000..e40a5bb4e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js @@ -0,0 +1,3 @@ +const foo = (arg) => { + return typeof arg === 'string'; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js.snap.json new file mode 100644 index 000000000..a337d1442 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/arrow/type-predicate2.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > ArrowFunction" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js new file mode 100644 index 000000000..87dffad27 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js @@ -0,0 +1,5 @@ +let a; +// the default param value is resolved to the outer scope +function foo(b = a) { + let a; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js.snap.json new file mode 100644 index 000000000..477a0dfd0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-body-shadow.js.snap.json @@ -0,0 +1,32 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js new file mode 100644 index 000000000..def360de5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js @@ -0,0 +1,2 @@ +const a = 0; +function foo(b = a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js.snap.json new file mode 100644 index 000000000..38d8a2da7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-const.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js new file mode 100644 index 000000000..5820a5f70 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js @@ -0,0 +1,2 @@ +let a; +function foo(b = a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js.snap.json new file mode 100644 index 000000000..38d8a2da7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-let.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js new file mode 100644 index 000000000..fc7edfc0b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js @@ -0,0 +1,6 @@ +let a; +function foo(b = function () { + a; +}) { + let a; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js.snap.json new file mode 100644 index 000000000..adb89868d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested-body-shadow.js.snap.json @@ -0,0 +1,45 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js new file mode 100644 index 000000000..b3038a410 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js @@ -0,0 +1,4 @@ +let a; +function foo(b = function () { + return a; +}) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js.snap.json new file mode 100644 index 000000000..f75a760d7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-nested.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js new file mode 100644 index 000000000..761ac2558 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js @@ -0,0 +1,3 @@ +let a; +// the default param value is resolved to the parameter +function foo(b = a, a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js.snap.json new file mode 100644 index 000000000..dd625a1a7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-param-shadow.js.snap.json @@ -0,0 +1,31 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a", + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js new file mode 100644 index 000000000..4c3f5b9bd --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js @@ -0,0 +1,2 @@ +let a; +function foo(b = a.c) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js.snap.json new file mode 100644 index 000000000..38d8a2da7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/readable-ref-partial.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js new file mode 100644 index 000000000..b283075b2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js @@ -0,0 +1 @@ +function foo(a, b = 0) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js.snap.json new file mode 100644 index 000000000..97cba679b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/default-params/writable-ref.js.snap.json @@ -0,0 +1,25 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a", + "b" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js new file mode 100644 index 000000000..99656fb7c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js @@ -0,0 +1,4 @@ +const parentScoped = 1; +function foo() { + parentScoped + 1; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js.snap.json new file mode 100644 index 000000000..c497794b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/inherited-scope.js.snap.json @@ -0,0 +1,28 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "parentScoped" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "parentScoped", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js new file mode 100644 index 000000000..c76d9d45d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js @@ -0,0 +1,4 @@ +function Foo() { + const Foo = 1; +} +const usage = Foo; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js.snap.json new file mode 100644 index 000000000..030de67c4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/name-shadowed-in-body.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "usage" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:Foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "Foo" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js new file mode 100644 index 000000000..119ae0a4c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js @@ -0,0 +1,3 @@ +function foo(a, b) { + a; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js.snap.json new file mode 100644 index 000000000..613b9ae0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/overload.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a", + "b" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js new file mode 100644 index 000000000..70e410dfb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js @@ -0,0 +1,5 @@ +const outer = 1; +function foo(a, [b], { c }, d = 1, e = a, f = outer, g) { + a; +} +const unresolved = g; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js.snap.json new file mode 100644 index 000000000..30252592e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/params.js.snap.json @@ -0,0 +1,51 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "outer", + "unresolved" + ], + "references": [ + { + "name": "g", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f", + "g" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:foo" + }, + { + "name": "outer", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js new file mode 100644 index 000000000..eca804b22 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js @@ -0,0 +1,6 @@ +function foo() { + let i = 0; + var j = 20; + i; +} +const unresolved = j; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js.snap.json new file mode 100644 index 000000000..0f4f0f8d9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/scope.js.snap.json @@ -0,0 +1,37 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "unresolved" + ], + "references": [ + { + "name": "j", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "j" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "i" + ], + "references": [ + { + "name": "i", + "declaredAt": "Program > FunctionDeclaration:foo > BlockStatement" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js new file mode 100644 index 000000000..99ecd9047 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js @@ -0,0 +1,3 @@ +function foo() { + let x; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js.snap.json new file mode 100644 index 000000000..a06b0b4e1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/body-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "x" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js new file mode 100644 index 000000000..a4cc7fc4b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js @@ -0,0 +1 @@ +function foo(a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/param-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js new file mode 100644 index 000000000..e2312a2d6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js @@ -0,0 +1 @@ +function foo() { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js.snap.json new file mode 100644 index 000000000..d3ec2eb74 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/return-value-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js new file mode 100644 index 000000000..e2312a2d6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js @@ -0,0 +1 @@ +function foo() { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js.snap.json new file mode 100644 index 000000000..d3ec2eb74 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-param-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js new file mode 100644 index 000000000..e2312a2d6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js @@ -0,0 +1 @@ +function foo() { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js.snap.json new file mode 100644 index 000000000..d3ec2eb74 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-parameters/type-parameter-declaration.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js new file mode 100644 index 000000000..d0ca48a11 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js @@ -0,0 +1 @@ +function foo(arg) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js.snap.json new file mode 100644 index 000000000..9d413c994 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts1.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js new file mode 100644 index 000000000..d0ca48a11 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js @@ -0,0 +1 @@ +function foo(arg) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js.snap.json new file mode 100644 index 000000000..9d413c994 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate-asserts2.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js new file mode 100644 index 000000000..1c688fe3d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js @@ -0,0 +1,3 @@ +function foo(arg) { + return typeof arg === 'string'; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js.snap.json new file mode 100644 index 000000000..b89814370 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate1.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js new file mode 100644 index 000000000..1c688fe3d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js @@ -0,0 +1,3 @@ +function foo(arg) { + return typeof arg === 'string'; +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js.snap.json new file mode 100644 index 000000000..b89814370 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-declaration/type-predicate2.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js new file mode 100644 index 000000000..373a21406 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js @@ -0,0 +1 @@ +const foo = function () { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js.snap.json new file mode 100644 index 000000000..becd50173 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/anonymous.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js new file mode 100644 index 000000000..3159efb93 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js @@ -0,0 +1,5 @@ +let a; +// the default param value is resolved to the outer scope +let foo = function (b = a) { + let a; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js.snap.json new file mode 100644 index 000000000..3c83223b7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-body-shadow.js.snap.json @@ -0,0 +1,32 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js new file mode 100644 index 000000000..8fb3821a6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js @@ -0,0 +1,2 @@ +const a = 0; +let foo = function (b = a) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js.snap.json new file mode 100644 index 000000000..202cca1af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-const.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js new file mode 100644 index 000000000..a9dbcb4b5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js @@ -0,0 +1,2 @@ +let a; +let foo = function (b = a) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js.snap.json new file mode 100644 index 000000000..202cca1af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-let.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js new file mode 100644 index 000000000..ccc838e43 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js @@ -0,0 +1,6 @@ +let a; +let foo = function (b = function () { + a; +}) { + let a; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js.snap.json new file mode 100644 index 000000000..a74e66e39 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested-body-shadow.js.snap.json @@ -0,0 +1,45 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [ + "a" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js new file mode 100644 index 000000000..1324261b0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js @@ -0,0 +1,4 @@ +let a; +let foo = function (b = function () { + return a; +}) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js.snap.json new file mode 100644 index 000000000..5e415597d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-nested.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + }, + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js new file mode 100644 index 000000000..3a2644730 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js @@ -0,0 +1,3 @@ +let a; +// the default param value is resolved to the parameter +let foo = function (b = a, a) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js.snap.json new file mode 100644 index 000000000..f3838d97c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-param-shadow.js.snap.json @@ -0,0 +1,31 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js new file mode 100644 index 000000000..d96d99a33 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js @@ -0,0 +1,2 @@ +let a; +let foo = function (b = a.c) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js.snap.json new file mode 100644 index 000000000..202cca1af --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/readable-ref-partial.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "a", + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "b" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js new file mode 100644 index 000000000..91c821269 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js @@ -0,0 +1 @@ +let foo = function (a, b = 0) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js.snap.json new file mode 100644 index 000000000..56294d853 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/default-params/writable-ref.js.snap.json @@ -0,0 +1,25 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js new file mode 100644 index 000000000..362a9cda0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js @@ -0,0 +1,4 @@ +const parentScoped = 1; +const foo = function () { + parentScoped + 1; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js.snap.json new file mode 100644 index 000000000..3006fb199 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/inherited-scope.js.snap.json @@ -0,0 +1,28 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "parentScoped" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "parentScoped", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js new file mode 100644 index 000000000..8f755fd0b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js @@ -0,0 +1,5 @@ +const outer = 1; +const foo = function (a, [b], { c }, d = 1, e = a, f = outer, g) { + a; +}; +const unresolved = g; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js.snap.json new file mode 100644 index 000000000..87c99fdfc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/params.js.snap.json @@ -0,0 +1,51 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "outer", + "unresolved" + ], + "references": [ + { + "name": "g", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a", + "b", + "c", + "d", + "e", + "f", + "g" + ], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "outer", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "a", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js new file mode 100644 index 000000000..f02b67650 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js @@ -0,0 +1,6 @@ +const foo = function () { + let i = 0; + var j = 20; + i; +}; +const unresolved = j; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js.snap.json new file mode 100644 index 000000000..715f8c04f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/scope.js.snap.json @@ -0,0 +1,37 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "unresolved" + ], + "references": [ + { + "name": "j", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "j" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "i" + ], + "references": [ + { + "name": "i", + "declaredAt": "Program > FunctionExpression > BlockStatement" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js new file mode 100644 index 000000000..9d1252703 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js @@ -0,0 +1,3 @@ +const foo = function () { + let x; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js.snap.json new file mode 100644 index 000000000..cb6a6de52 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/body-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "x" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js new file mode 100644 index 000000000..b00057650 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js @@ -0,0 +1 @@ +const foo = function (a) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js.snap.json new file mode 100644 index 000000000..4a396499e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/param-reference.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js new file mode 100644 index 000000000..373a21406 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js @@ -0,0 +1 @@ +const foo = function () { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js.snap.json new file mode 100644 index 000000000..becd50173 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/return-value-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js new file mode 100644 index 000000000..373a21406 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js @@ -0,0 +1 @@ +const foo = function () { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js.snap.json new file mode 100644 index 000000000..becd50173 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-param-reference.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js new file mode 100644 index 000000000..373a21406 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js @@ -0,0 +1 @@ +const foo = function () { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js.snap.json new file mode 100644 index 000000000..becd50173 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-parameters/type-parameter-declaration.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js new file mode 100644 index 000000000..f06b75661 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js @@ -0,0 +1 @@ +const foo = function (arg) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js.snap.json new file mode 100644 index 000000000..c0605c864 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts1.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js new file mode 100644 index 000000000..f06b75661 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js @@ -0,0 +1 @@ +const foo = function (arg) { }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js.snap.json new file mode 100644 index 000000000..c0605c864 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate-asserts2.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js new file mode 100644 index 000000000..4ca49ea49 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js @@ -0,0 +1,3 @@ +const foo = function (arg) { + return typeof arg === 'string'; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js.snap.json new file mode 100644 index 000000000..45dc9ec32 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate1.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js new file mode 100644 index 000000000..4ca49ea49 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js @@ -0,0 +1,3 @@ +const foo = function (arg) { + return typeof arg === 'string'; +}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js.snap.json new file mode 100644 index 000000000..45dc9ec32 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/functions/function-expression/type-predicate2.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "arg", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js new file mode 100644 index 000000000..2f4d8e619 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js @@ -0,0 +1,4 @@ +//// @sourceType = module +class Foo { +} +new Foo(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js.snap.json new file mode 100644 index 000000000..33a3907d9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/class.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js new file mode 100644 index 000000000..106a0edd3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js @@ -0,0 +1,3 @@ +//// @sourceType = module +function top() { } +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js.snap.json new file mode 100644 index 000000000..97cbefe8c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/function.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:top", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js new file mode 100644 index 000000000..e5ff6af2e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-const.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js new file mode 100644 index 000000000..cf14e6e6f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js @@ -0,0 +1,3 @@ +//// @sourceType = module +let top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-let.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js new file mode 100644 index 000000000..36eb940c3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js @@ -0,0 +1,3 @@ +//// @sourceType = module +var top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/module/variable-decl-var.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js new file mode 100644 index 000000000..3f7bde671 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js @@ -0,0 +1,4 @@ +//// @sourceType = script +class Foo { +} +new Foo(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js.snap.json new file mode 100644 index 000000000..33a3907d9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/class.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js new file mode 100644 index 000000000..b7249be29 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js @@ -0,0 +1,3 @@ +//// @sourceType = script +function top() { } +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js.snap.json new file mode 100644 index 000000000..97cbefe8c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/function.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:top", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js new file mode 100644 index 000000000..a540fe4ba --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js @@ -0,0 +1,3 @@ +//// @sourceType = script +const top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-const.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js new file mode 100644 index 000000000..925c1b9f8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js @@ -0,0 +1,3 @@ +//// @sourceType = script +let top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-let.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js new file mode 100644 index 000000000..cf024bd7f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js @@ -0,0 +1,3 @@ +//// @sourceType = script +var top = () => { }; +top(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js.snap.json new file mode 100644 index 000000000..f65d12ebc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/global-resolution/script/variable-decl-var.js.snap.json @@ -0,0 +1,27 @@ +{ + "type": "Program", + "declarations": [ + "top" + ], + "references": [ + { + "name": "top", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js new file mode 100644 index 000000000..89a08efd8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js @@ -0,0 +1 @@ +const x = y; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js.snap.json new file mode 100644 index 000000000..9e1c4f342 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/implicit/implicit1.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "y", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js new file mode 100644 index 000000000..d5997be91 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js @@ -0,0 +1,3 @@ +//// @sourceType = module +import v from 'foo'; +v; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js.snap.json new file mode 100644 index 000000000..20cab1f82 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/default.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "v" + ], + "references": [ + { + "name": "v", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js new file mode 100644 index 000000000..b38efea52 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js @@ -0,0 +1,3 @@ +//// @sourceType = module +foo; +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js.snap.json new file mode 100644 index 000000000..f7dad41f9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals1.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js new file mode 100644 index 000000000..c1deccbdb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const x = 1; +var foo = x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js.snap.json new file mode 100644 index 000000000..baec643cf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/equals2.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "foo", + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js new file mode 100644 index 000000000..3271e375e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js @@ -0,0 +1,3 @@ +//// @sourceType = module +import { v as t } from 'foo'; +t; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js.snap.json new file mode 100644 index 000000000..cef8ada21 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named-alias.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "t" + ], + "references": [ + { + "name": "t", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js new file mode 100644 index 000000000..10dfc8a70 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js @@ -0,0 +1,3 @@ +//// @sourceType = module +import { v } from 'foo'; +v; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js.snap.json new file mode 100644 index 000000000..20cab1f82 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/named.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "v" + ], + "references": [ + { + "name": "v", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js new file mode 100644 index 000000000..0c855b606 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js @@ -0,0 +1,3 @@ +//// @sourceType = module +import * as v from 'foo'; +v; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js.snap.json new file mode 100644 index 000000000..20cab1f82 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/namespace.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "v" + ], + "references": [ + { + "name": "v", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default-value.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js new file mode 100644 index 000000000..15c86c392 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const unresolved = T; +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js.snap.json new file mode 100644 index 000000000..f9a4188d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-default.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "unresolved" + ], + "references": [ + { + "name": "T", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline-value.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js new file mode 100644 index 000000000..15c86c392 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const unresolved = T; +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js.snap.json new file mode 100644 index 000000000..f9a4188d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-inline.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "unresolved" + ], + "references": [ + { + "name": "T", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js new file mode 100644 index 000000000..89f94bfae --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js @@ -0,0 +1,2 @@ +//// @sourceType = module +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named-value.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js new file mode 100644 index 000000000..15c86c392 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js @@ -0,0 +1,3 @@ +//// @sourceType = module +const unresolved = T; +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js.snap.json new file mode 100644 index 000000000..f9a4188d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/import/type-named.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "unresolved" + ], + "references": [ + { + "name": "T", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js new file mode 100644 index 000000000..f5cb89dc1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js @@ -0,0 +1,8 @@ +class Foo { +} +class Bar { + constructor() { + this.foo = (Foo); + } +} +new Bar(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js.snap.json new file mode 100644 index 000000000..0e3881a71 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments1.js.snap.json @@ -0,0 +1,33 @@ +{ + "type": "Program", + "declarations": [ + "Bar", + "Foo" + ], + "references": [ + { + "name": "Bar", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js new file mode 100644 index 000000000..58112b736 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js @@ -0,0 +1,4 @@ +function makeBox(value) { + return { value }; +} +const makeStringBox = (makeBox); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js.snap.json new file mode 100644 index 000000000..10750ae2a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/instantiation-expressions/type-arguments2.js.snap.json @@ -0,0 +1,35 @@ +{ + "type": "Program", + "declarations": [ + "makeBox", + "makeStringBox" + ], + "references": [ + { + "name": "makeBox", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:makeBox", + "declarations": [ + "value" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "value", + "declaredAt": "Program > FunctionDeclaration:makeBox" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js new file mode 100644 index 000000000..e885d85b2 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js @@ -0,0 +1,3 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const x = {}; +_jsx(Foo, { ...x }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js.snap.json new file mode 100644 index 000000000..13e374114 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute-spread.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "_jsx", + "x" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + }, + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js new file mode 100644 index 000000000..f0f30446b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js @@ -0,0 +1,4 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const x = 1; +const attr = 2; // should be unreferenced +_jsx(Foo, { attr: x }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js.snap.json new file mode 100644 index 000000000..4841c6c26 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/attribute.js.snap.json @@ -0,0 +1,23 @@ +{ + "type": "Program", + "declarations": [ + "_jsx", + "attr", + "x" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + }, + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js new file mode 100644 index 000000000..f23dbd967 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js @@ -0,0 +1,3 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const child = 1; +_jsx(Foo, { children: child }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js.snap.json new file mode 100644 index 000000000..ca06b6f5d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/children.js.snap.json @@ -0,0 +1,22 @@ +{ + "type": "Program", + "declarations": [ + "_jsx", + "child" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + }, + { + "name": "child", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js new file mode 100644 index 000000000..c266d55b5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js @@ -0,0 +1,3 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +function div() { } // should not be referenced +_jsx("div", {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js.snap.json new file mode 100644 index 000000000..cf39c1fa7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-intrinsic-name.js.snap.json @@ -0,0 +1,28 @@ +{ + "type": "Program", + "declarations": [ + "_jsx", + "div" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:div", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js new file mode 100644 index 000000000..c2583279d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js @@ -0,0 +1,6 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const X = { + Foo() { }, +}; +const Foo = 1; // should be unreferenced +_jsx(X.Foo, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js.snap.json new file mode 100644 index 000000000..66df04f1e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced1.js.snap.json @@ -0,0 +1,33 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "X", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "X", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js new file mode 100644 index 000000000..36819cd92 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js @@ -0,0 +1,6 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +const x = { + Foo() { }, +}; +const Foo = 1; // should be unreferenced +_jsx(x.Foo, {}); // lower cased namespaces should still create a reference diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js.snap.json new file mode 100644 index 000000000..0110947f0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component-namespaced2.js.snap.json @@ -0,0 +1,33 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "_jsx", + "x" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js new file mode 100644 index 000000000..4fb40d3fa --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js @@ -0,0 +1,3 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +function Foo() { } +_jsx(Foo, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js.snap.json new file mode 100644 index 000000000..2b0527a8d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/component.js.snap.json @@ -0,0 +1,32 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:Foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js new file mode 100644 index 000000000..a70097545 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js @@ -0,0 +1,4 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +import React from 'react'; +_jsx(_Fragment, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js.snap.json new file mode 100644 index 000000000..48fc414b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxFragmentName.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js new file mode 100644 index 000000000..a70097545 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js @@ -0,0 +1,4 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +import React from 'react'; +_jsx(_Fragment, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js.snap.json new file mode 100644 index 000000000..48fc414b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma-fragment.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js new file mode 100644 index 000000000..120557012 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js @@ -0,0 +1,4 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +import React from 'react'; +_jsx(Foo, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js.snap.json new file mode 100644 index 000000000..d47d81d34 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/default-jsxPragma.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js new file mode 100644 index 000000000..0b5105b91 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js @@ -0,0 +1,5 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +//// @jsxFragmentName = 'Fragment' +import React from 'react'; // should be unreferenced +_jsx(_Fragment, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js.snap.json new file mode 100644 index 000000000..48fc414b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxFragmentName.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js new file mode 100644 index 000000000..5521dc383 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js @@ -0,0 +1,6 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +//// @jsxPragma = 'h' +//// @jsxFragmentName = 'Fragment' +import React from 'react'; // should be unreferenced +_jsx(_Fragment, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js.snap.json new file mode 100644 index 000000000..48fc414b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma-jsxFragmentName.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js new file mode 100644 index 000000000..50a6c4163 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js @@ -0,0 +1,5 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +//// @sourceType = 'module' +//// @jsxPragma = 'h' +import React from 'react'; // should be unreferenced +_jsx(Foo, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js.snap.json new file mode 100644 index 000000000..d47d81d34 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/factory/jsxPragma.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "React", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js new file mode 100644 index 000000000..48438b78e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js @@ -0,0 +1,3 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +const child = 1; +_jsx(_Fragment, { children: child }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js.snap.json new file mode 100644 index 000000000..f9e8454ff --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment-children.js.snap.json @@ -0,0 +1,23 @@ +{ + "type": "Program", + "declarations": [ + "_Fragment", + "_jsx", + "child" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + }, + { + "name": "child", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js new file mode 100644 index 000000000..1df8c5f09 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js @@ -0,0 +1,2 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +_jsx(_Fragment, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js.snap.json new file mode 100644 index 000000000..8af8dbd47 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/fragment.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js new file mode 100644 index 000000000..e344cf6fa --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js @@ -0,0 +1,2 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +_jsx(Foo, {}); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js.snap.json new file mode 100644 index 000000000..df2306009 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/generic-type-param.js.snap.json @@ -0,0 +1,17 @@ +{ + "type": "Program", + "declarations": [ + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js new file mode 100644 index 000000000..c661cf448 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js @@ -0,0 +1,8 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +import * as React from 'react'; +// Both of these are equivalent: +const x = _jsx(Foo, { "a:b": "hello" }); +const y = _jsx(Foo, { "a:b": "hello" }); +function Foo(props) { + return _jsx("div", { children: props['a:b'] }); +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js.snap.json new file mode 100644 index 000000000..a1d66c6e3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/namespaced-attribute.js.snap.json @@ -0,0 +1,54 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "React", + "_jsx", + "x", + "y" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:Foo", + "declarations": [ + "props" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "props", + "declaredAt": "Program > FunctionDeclaration:Foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js new file mode 100644 index 000000000..38adecfc6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js @@ -0,0 +1,3 @@ +import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; +const Foo = 1; // should be unreferenced +_jsx(_Fragment, { children: "Foo" }); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js.snap.json new file mode 100644 index 000000000..7b071664f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/text.js.snap.json @@ -0,0 +1,19 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "_Fragment", + "_jsx" + ], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_Fragment", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js new file mode 100644 index 000000000..502ab3f89 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js @@ -0,0 +1,12 @@ +import { jsx as _jsx } from "react/jsx-runtime"; +class Foo { + constructor() { + this.Div = { + Element: () => _jsx("div", {}), + }; + } + method() { + _jsx(this.foo, {}); + (_jsx(Div.Element, {}))(_jsx(this, {})); + } +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js.snap.json new file mode 100644 index 000000000..eaff33948 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/jsx/this-jsxidentifier.js.snap.json @@ -0,0 +1,65 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "_jsx" + ], + "references": [], + "children": [ + { + "type": "FunctionExpression", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [ + { + "type": "ArrowFunction", + "declarations": [], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] + }, + { + "type": "FunctionExpression[2]", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "_jsx", + "declaredAt": "Program" + }, + { + "name": "Div", + "declaredAt": null + }, + { + "name": "_jsx", + "declaredAt": "Program" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js new file mode 100644 index 000000000..4051c2082 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js @@ -0,0 +1,6 @@ +const x = {}; +x.a; +x.a.b.c.d; +x['a']; +x?.a.b.c; +x?.['a']; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js.snap.json new file mode 100644 index 000000000..51d60c6c7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/member-expression/member-expression.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js new file mode 100644 index 000000000..3e9dee8fc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js @@ -0,0 +1,4 @@ +class Foo { +} +const a = 1; +new Foo(a); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js.snap.json new file mode 100644 index 000000000..a7af778bc --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/new-expression.js.snap.json @@ -0,0 +1,18 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "a" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "a", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js new file mode 100644 index 000000000..ac22183e8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js @@ -0,0 +1 @@ +new Foo(); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js.snap.json new file mode 100644 index 000000000..1b8775793 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters1.js.snap.json @@ -0,0 +1,11 @@ +{ + "type": "Program", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js new file mode 100644 index 000000000..aa27364d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js @@ -0,0 +1,2 @@ +const T = 1; +new Foo(); // should not resolve to value diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js.snap.json new file mode 100644 index 000000000..ed28dc095 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/new-expression/type-parameters2.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "T" + ], + "references": [ + { + "name": "Foo", + "declaredAt": null + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js new file mode 100644 index 000000000..2cc324fb7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 1] = "a"; +})(Foo || (Foo = {})); +Foo.a; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js.snap.json new file mode 100644 index 000000000..bff2f2528 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/external-ref.js.snap.json @@ -0,0 +1,46 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js new file mode 100644 index 000000000..93c461cb3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 1] = "a"; + Foo[Foo["b"] = 1] = "b"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js.snap.json new file mode 100644 index 000000000..524ba043c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member-ref.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js new file mode 100644 index 000000000..3c7064b26 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js @@ -0,0 +1,4 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 1] = "a"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js.snap.json new file mode 100644 index 000000000..6f3ceb795 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/literal-member.js.snap.json @@ -0,0 +1,42 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js new file mode 100644 index 000000000..93c461cb3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 1] = "a"; + Foo[Foo["b"] = 1] = "b"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js.snap.json new file mode 100644 index 000000000..524ba043c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/member-ref.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js new file mode 100644 index 000000000..9292f93b4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +const unresolved = a; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js.snap.json new file mode 100644 index 000000000..20efa3aa5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/scope.js.snap.json @@ -0,0 +1,47 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "unresolved" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "a", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js new file mode 100644 index 000000000..93c461cb3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 1] = "a"; + Foo[Foo["b"] = 1] = "b"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js.snap.json new file mode 100644 index 000000000..524ba043c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-enum/self-ref.js.snap.json @@ -0,0 +1,50 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js new file mode 100644 index 000000000..d2b1f9430 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js @@ -0,0 +1,6 @@ +class Foo { +} +(function (Foo) { + Foo.x = 1; +})(Foo || (Foo = {})); +const usage = Foo; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js.snap.json new file mode 100644 index 000000000..8fb8af2ed --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/class-namespace.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "usage" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js new file mode 100644 index 000000000..cdfff0ec6 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js @@ -0,0 +1,5 @@ +function Foo() { } +(function (Foo) { + Foo.x = 1; +})(Foo || (Foo = {})); +const usage = Foo; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js.snap.json new file mode 100644 index 000000000..4f72d799f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/function-namespace.js.snap.json @@ -0,0 +1,56 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "usage" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:Foo", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + }, + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js new file mode 100644 index 000000000..a566d2b19 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js @@ -0,0 +1,2 @@ +const Foo = 1; +const usage = Foo; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js.snap.json new file mode 100644 index 000000000..baf771c0b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/declaration-merging/namespace-variable.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "usage" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js new file mode 100644 index 000000000..d82b6d3c1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo.x = 1; +})(Foo || (Foo = {})); +Foo.x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js.snap.json new file mode 100644 index 000000000..4ed6df404 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/external-ref.js.snap.json @@ -0,0 +1,42 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js new file mode 100644 index 000000000..af10d5310 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js @@ -0,0 +1 @@ +//// @sourceType = module diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/global-augmentation.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js new file mode 100644 index 000000000..af10d5310 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js @@ -0,0 +1 @@ +//// @sourceType = module diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/import.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js new file mode 100644 index 000000000..59d752b7e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo_1) { + Foo_1.Foo = 1; +})(Foo || (Foo = {})); +const usage = Foo; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js.snap.json new file mode 100644 index 000000000..46443b4e7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/name-shadowed-in-body.js.snap.json @@ -0,0 +1,43 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "usage" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo_1" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo_1", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js new file mode 100644 index 000000000..48ec9763a --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js @@ -0,0 +1,7 @@ +var Foo; +(function (Foo) { + Foo.x = 1; + Foo.x; +})(Foo || (Foo = {})); +const unresolved = x; +Foo.x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js.snap.json new file mode 100644 index 000000000..5aa3a6c58 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/namespace.js.snap.json @@ -0,0 +1,51 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "unresolved" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": null + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js new file mode 100644 index 000000000..060980be7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js @@ -0,0 +1,8 @@ +export var A; +(function (A) { + let X; + (function (X) { + X.Y = 1; + })(X = A.X || (A.X = {})); +})(A || (A = {})); +const X = 23; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js.snap.json new file mode 100644 index 000000000..a96247d04 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/nested-namespace-alias.js.snap.json @@ -0,0 +1,70 @@ +{ + "type": "Program", + "declarations": [ + "A", + "X" + ], + "references": [ + { + "name": "A", + "declaredAt": "Program" + }, + { + "name": "A", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "A" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "X" + ], + "references": [ + { + "name": "X", + "declaredAt": "Program > FunctionExpression > BlockStatement" + }, + { + "name": "A", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "A", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "X" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "X", + "declaredAt": "Program > FunctionExpression > BlockStatement > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js new file mode 100644 index 000000000..7b16268a1 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + const x = 1; +})(Foo || (Foo = {})); +const unresolved = x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js.snap.json new file mode 100644 index 000000000..12c89bd6b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/scope.js.snap.json @@ -0,0 +1,40 @@ +{ + "type": "Program", + "declarations": [ + "Foo", + "unresolved" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "x", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "x" + ], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js new file mode 100644 index 000000000..f5d071d55 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js @@ -0,0 +1,5 @@ +var Foo; +(function (Foo) { + Foo.x = 1; + Foo.x; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js.snap.json new file mode 100644 index 000000000..6f3ceb795 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/ts-module/self-ref.js.snap.json @@ -0,0 +1,42 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js new file mode 100644 index 000000000..61f037f51 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js @@ -0,0 +1 @@ +function foo([a]) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-array-destructure.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js new file mode 100644 index 000000000..7540c0d39 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js @@ -0,0 +1 @@ +function foo(a = 1) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-default.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js new file mode 100644 index 000000000..df2a48f1f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js @@ -0,0 +1 @@ +function foo({ a }) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-object-destructure.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js new file mode 100644 index 000000000..09a5402c7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js @@ -0,0 +1 @@ +function foo(...a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter-rest.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js new file mode 100644 index 000000000..a4cc7fc4b --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js @@ -0,0 +1 @@ +function foo(a) { } diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js.snap.json new file mode 100644 index 000000000..8c438e1f5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/parameter.js.snap.json @@ -0,0 +1,24 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "a" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js new file mode 100644 index 000000000..e8483fadf --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js @@ -0,0 +1 @@ +const [x] = []; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-array-destructure.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js new file mode 100644 index 000000000..943c458c7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js @@ -0,0 +1 @@ +const x = 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-const.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js new file mode 100644 index 000000000..2756c24c4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js @@ -0,0 +1 @@ +let x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-let.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js new file mode 100644 index 000000000..d7cb93de4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js @@ -0,0 +1 @@ +const { x } = {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-object-destructure.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js new file mode 100644 index 000000000..96f6d3a3f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js @@ -0,0 +1 @@ +var x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-annotation/variable-var.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js new file mode 100644 index 000000000..67a65d961 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js @@ -0,0 +1,2 @@ +const x = 1; +x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/angle-bracket.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js new file mode 100644 index 000000000..67a65d961 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js @@ -0,0 +1,2 @@ +const x = 1; +x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/as.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js new file mode 100644 index 000000000..32770881d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js @@ -0,0 +1,2 @@ +let x = 1; +x += 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/angle-bracket-assignment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js new file mode 100644 index 000000000..32770881d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js @@ -0,0 +1,2 @@ +let x = 1; +x += 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/as-assignment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js new file mode 100644 index 000000000..32770881d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js @@ -0,0 +1,2 @@ +let x = 1; +x += 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/assignment/non-null-assignment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js new file mode 100644 index 000000000..3c7d487eb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js @@ -0,0 +1,2 @@ +let x = 1; +x++; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/angle-bracket-increment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js new file mode 100644 index 000000000..3c7d487eb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js @@ -0,0 +1,2 @@ +let x = 1; +x++; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/as-increment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js new file mode 100644 index 000000000..3c7d487eb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js @@ -0,0 +1,2 @@ +let x = 1; +x++; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/increment/non-null-increment.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js new file mode 100644 index 000000000..67a65d961 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js @@ -0,0 +1,2 @@ +const x = 1; +x; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js.snap.json new file mode 100644 index 000000000..b533a0e0d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-assertion/satisfies.js.snap.json @@ -0,0 +1,13 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [ + { + "name": "x", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional-nested.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional-nested.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional-nested.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional-nested.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional-nested.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional3.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional3.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional3.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional4.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional4.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional4.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional4.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional4.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional5.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional5.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional5.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional5.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/conditional5.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js new file mode 100644 index 000000000..7ed3d445c --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js @@ -0,0 +1,2 @@ +const dual = 1; +const reference2 = dual; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js.snap.json new file mode 100644 index 000000000..445a7a49f --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/dual-type-value.js.snap.json @@ -0,0 +1,14 @@ +{ + "type": "Program", + "declarations": [ + "dual", + "reference2" + ], + "references": [ + { + "name": "dual", + "declaredAt": "Program" + } + ], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor-generics2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/constructor.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function-generics2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js new file mode 100644 index 000000000..800ffc2d8 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js @@ -0,0 +1 @@ +const arg = 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js.snap.json new file mode 100644 index 000000000..287d4d53e --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/function2.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "arg" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/array-pattern.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/array-pattern.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/array-pattern.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/array-pattern.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/array-pattern.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/object-pattern.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/object-pattern.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/object-pattern.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/object-pattern.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/object-pattern.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/rest-element.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/rest-element.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/rest-element.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/rest-element.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/function/params/rest-element.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-qualifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-qualifier.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-qualifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-qualifier.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-qualifier.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-type-params.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-type-params.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-type-params.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-type-params.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type-with-type-params.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/import-type.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js new file mode 100644 index 000000000..6f2abd859 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js @@ -0,0 +1 @@ +const k = 'a'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js.snap.json new file mode 100644 index 000000000..682f6e2e4 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/index-access3.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "k" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/infer-type-constraint.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/infer-type-constraint.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/infer-type-constraint.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/infer-type-constraint.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/infer-type-constraint.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface-heritage2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/interface2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type3.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type3.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/literal-type3.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-no-references.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-no-references.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-no-references.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-no-references.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-no-references.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-referenced.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-referenced.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-referenced.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-referenced.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named-literal-referenced.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped-named.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/mapped.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/qualified-name.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/qualified-name.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/qualified-name.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/qualified-name.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/qualified-name.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call-generics.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call-generics.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call-generics.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call-generics.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call-generics.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/call.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct-generics.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct-generics.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct-generics.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct-generics.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct-generics.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/construct.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/index-sig.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/index-sig.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/index-sig.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/index-sig.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/index-sig.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js new file mode 100644 index 000000000..eba059f77 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js @@ -0,0 +1 @@ +const x = 'b'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js new file mode 100644 index 000000000..9d3396dce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js @@ -0,0 +1,4 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js.snap.json new file mode 100644 index 000000000..6f3ceb795 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-computed-name2.js.snap.json @@ -0,0 +1,42 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-generics.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-generics.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-generics.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-generics.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method-generics.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/method.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js new file mode 100644 index 000000000..eba059f77 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js @@ -0,0 +1 @@ +const x = 'b'; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js new file mode 100644 index 000000000..9d3396dce --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js @@ -0,0 +1,4 @@ +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js.snap.json new file mode 100644 index 000000000..6f3ceb795 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property-computed-name2.js.snap.json @@ -0,0 +1,42 @@ +{ + "type": "Program", + "declarations": [ + "Foo" + ], + "references": [ + { + "name": "Foo", + "declaredAt": "Program" + }, + { + "name": "Foo", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionExpression", + "declarations": [ + "Foo" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + }, + { + "name": "Foo", + "declaredAt": "Program > FunctionExpression" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/signatures/property.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled-rest.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled-rest.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled-rest.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled-rest.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled-rest.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-labelled.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-rest.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-rest.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-rest.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-rest.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple-rest.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/tuple.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/body-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/body-reference.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/body-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/body-reference.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/body-reference.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/extends-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/extends-reference.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/extends-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/extends-reference.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/extends-reference.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-param-reference.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-param-reference.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-param-reference.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration-extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration-extends.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration-extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration-extends.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration-extends.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/interface/type-parameter-declaration.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js new file mode 100644 index 000000000..d799f9e86 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js @@ -0,0 +1,2 @@ +function div(arg) { } +const StyledPayment = div ``; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js.snap.json new file mode 100644 index 000000000..002ea5f54 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/tagged-template.js.snap.json @@ -0,0 +1,30 @@ +{ + "type": "Program", + "declarations": [ + "StyledPayment", + "div" + ], + "references": [ + { + "name": "div", + "declaredAt": "Program" + } + ], + "children": [ + { + "type": "FunctionDeclaration:div", + "declarations": [ + "arg" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/body-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/body-reference.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/body-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/body-reference.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/body-reference.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-param-reference.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-param-reference.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-param-reference.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-param-reference.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-param-reference.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration-extends.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration-extends.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration-extends.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration-extends.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration-extends.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-parameters/type-decl/type-parameter-declaration.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js new file mode 100644 index 000000000..7ad627805 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js @@ -0,0 +1 @@ +const x = { y: { z: 1 } }; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-qualified.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js new file mode 100644 index 000000000..97337fde9 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js @@ -0,0 +1,4 @@ +function foo(y) { + return { y }; +} +export {}; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js.snap.json new file mode 100644 index 000000000..82e048e49 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query-with-parameters.js.snap.json @@ -0,0 +1,29 @@ +{ + "type": "Program", + "declarations": [ + "foo" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:foo", + "declarations": [ + "y" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "y", + "declaredAt": "Program > FunctionDeclaration:foo" + } + ], + "children": [] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js new file mode 100644 index 000000000..943c458c7 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js @@ -0,0 +1 @@ +const x = 1; diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js.snap.json new file mode 100644 index 000000000..266f19e90 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type-query.js.snap.json @@ -0,0 +1,8 @@ +{ + "type": "Program", + "declarations": [ + "x" + ], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type1.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type1.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type1.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type1.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type1.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type2.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type2.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type2.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type2.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type2.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type3.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type3.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type3.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type3.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/type3.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/typeof-import-type-with-qualifier.js b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/typeof-import-type-with-qualifier.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/typeof-import-type-with-qualifier.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/typeof-import-type-with-qualifier.js.snap.json new file mode 100644 index 000000000..377029499 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/typescript-eslint/type-declaration/typeof-import-type-with-qualifier.js.snap.json @@ -0,0 +1,6 @@ +{ + "type": "Program", + "declarations": [], + "references": [], + "children": [] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js b/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js new file mode 100644 index 000000000..ed135e0f0 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js @@ -0,0 +1,6 @@ +function f() { + { + var x = 1 + } + return x +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js.snap.json new file mode 100644 index 000000000..82deff7b3 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/var-hoisting.js.snap.json @@ -0,0 +1,36 @@ +{ + "type": "Program", + "declarations": [ + "f" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:f", + "declarations": [ + "x" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [ + { + "name": "x", + "declaredAt": "Program > FunctionDeclaration:f" + } + ], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js b/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js new file mode 100644 index 000000000..56bc7b4bb --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js @@ -0,0 +1,6 @@ +function outer() { + function inner() { + var x = 1 + } + return x +} diff --git a/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js.snap.json b/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js.snap.json new file mode 100644 index 000000000..97ea5e090 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/fixtures/scope/var-nested-fn.js.snap.json @@ -0,0 +1,45 @@ +{ + "type": "Program", + "declarations": [ + "outer" + ], + "references": [], + "children": [ + { + "type": "FunctionDeclaration:outer", + "declarations": [], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [ + "inner" + ], + "references": [ + { + "name": "x", + "declaredAt": null + } + ], + "children": [ + { + "type": "FunctionDeclaration:inner", + "declarations": [ + "x" + ], + "references": [], + "children": [ + { + "type": "BlockStatement", + "declarations": [], + "references": [], + "children": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/packages/plugin-rsc/src/transforms/hoist.test.ts b/packages/plugin-rsc/src/transforms/hoist.test.ts index 22742a470..2fac98e43 100644 --- a/packages/plugin-rsc/src/transforms/hoist.test.ts +++ b/packages/plugin-rsc/src/transforms/hoist.test.ts @@ -463,4 +463,538 @@ export async function test() { " `) }) + + // ok: should not bind + it('shadowing local if over local', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + const value = 0; + return value; + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + if (true) { + const value = 0; + return value; + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should not bind + it('shadowing local body over local', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + const value = 0; + return value; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + const value = 0; + return value; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should not bind + it('shadowing local body and if over local', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + const value = 0; + return value; + } + const value = 0; + return value; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + if (true) { + const value = 0; + return value; + } + const value = 0; + return value; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should bind + it('shadowing partial local over local', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); + } + + ;export async function $$hoist_0_action(value) { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should not bind + it('shadowing local over global', async () => { + const input = `\ +const value = 0; +function outer() { + async function action() { + "use server"; + if (true) { + const value = 1; + return value; + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "const value = 0; + function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + if (true) { + const value = 1; + return value; + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should not bind + it('shadowing partial local over global', async () => { + const input = `\ +const value = 0; +function outer() { + async function action() { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "const value = 0; + function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should not bind + it('shadowing local over local over global', async () => { + const input = `\ +const value = 0; +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + const value = 1; + return value; + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "const value = 0; + function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + if (true) { + const value = 1; + return value; + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // ok: should bind + it('shadowing partial local over local over global', async () => { + const input = `\ +const value = 0; +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "const value = 0; + function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); + } + + ;export async function $$hoist_0_action(value) { + "use server"; + if (true) { + const value = 1; + return value; + } + return value; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('deeper', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + if (true) { + return value; + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); + } + + ;export async function $$hoist_0_action(value) { + "use server"; + if (true) { + return value; + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('var hoisting', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + console.log({ value }) + var value = 1; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + console.log({ value }) + var value = 1; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('var hoisting block', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + console.log({ value }) + { + var value = 1; + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + console.log({ value }) + { + var value = 1; + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('function hoisting', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + console.log({ value }) + function value() {} + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action"); + } + + ;export async function $$hoist_0_action() { + "use server"; + console.log({ value }) + function value() {} + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('function hoisting block', async () => { + const input = `\ +function outer() { + const value = 0; + async function action() { + "use server"; + console.log({ value }) + { + function value() {} + } + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const value = 0; + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, value); + } + + ;export async function $$hoist_0_action(value) { + "use server"; + console.log({ value }) + { + function value() {} + } + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // TODO: check next.js + it('recursion', async () => { + const input = `\ +function outer() { + async function action() { + "use server"; + if (false) { + return action(); + } + return 0; + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, action); + } + + ;export async function $$hoist_0_action(action) { + "use server"; + if (false) { + return action(); + } + return 0; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + it('computed destructuring key in body', async () => { + const input = `\ +function outer() { + const key = 'value' + async function action(data) { + "use server"; + const { [key]: val } = data + return val + } +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + "function outer() { + const key = 'value' + const action = /* #__PURE__ */ $$register($$hoist_0_action, "", "$$hoist_0_action").bind(null, key); + } + + ;export async function $$hoist_0_action(key, data) { + "use server"; + const { [key]: val } = data + return val + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_action, "name", { value: "action" }); + " + `) + }) + + // TODO: check next.js + it('assignment', async () => { + const input = ` +function Counter() { + let local = 0; + + async function updateLocal() { + "use server"; + local = 1; + } + + return "something"; +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + " + function Counter() { + let local = 0; + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); + + return "something"; + } + + ;export async function $$hoist_0_updateLocal(local) { + "use server"; + local = 1; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); + " + `) + }) + + // TODO + it('increment', async () => { + const input = ` +function Counter() { + let local = 0; + + async function updateLocal() { + "use server"; + local++; + } + + return "something"; +} +` + expect(await testTransform(input)).toMatchInlineSnapshot(` + " + function Counter() { + let local = 0; + + const updateLocal = /* #__PURE__ */ $$register($$hoist_0_updateLocal, "", "$$hoist_0_updateLocal").bind(null, local); + + return "something"; + } + + ;export async function $$hoist_0_updateLocal(local) { + "use server"; + local++; + }; + /* #__PURE__ */ Object.defineProperty($$hoist_0_updateLocal, "name", { value: "updateLocal" }); + " + `) + }) }) diff --git a/packages/plugin-rsc/src/transforms/hoist.ts b/packages/plugin-rsc/src/transforms/hoist.ts index eb5bf15ba..ad926d1b0 100644 --- a/packages/plugin-rsc/src/transforms/hoist.ts +++ b/packages/plugin-rsc/src/transforms/hoist.ts @@ -1,8 +1,7 @@ -import { tinyassert } from '@hiogawa/utils' -import type { Program, Literal } from 'estree' +import type { Program, Literal, Node } from 'estree' import { walk } from 'estree-walker' import MagicString from 'magic-string' -import { analyze } from 'periscopic' +import { buildScopeTree, type ScopeTree } from './scope' export function transformHoistInlineDirective( input: string, @@ -37,19 +36,7 @@ export function transformHoistInlineDirective( ? exactRegex(options.directive) : options.directive - // re-export somehow confuses periscopic scopes so remove them before analysis - walk(ast, { - enter(node) { - if (node.type === 'ExportAllDeclaration') { - this.remove() - } - if (node.type === 'ExportNamedDeclaration' && !node.declaration) { - this.remove() - } - }, - }) - - const analyzed = analyze(ast) + const scopeTree = buildScopeTree(ast) const names: string[] = [] walk(ast, { @@ -71,8 +58,6 @@ export function transformHoistInlineDirective( ) } - const scope = analyzed.map.get(node) - tinyassert(scope) const declName = node.type === 'FunctionDeclaration' && node.id.name const originalName = declName || @@ -81,15 +66,7 @@ export function transformHoistInlineDirective( parent.id.name) || 'anonymous_server_function' - // bind variables which are neither global nor in own scope - const bindVars = [...scope.references].filter((ref) => { - // declared function itself is included as reference - if (ref === declName) { - return false - } - const owner = scope.find_owner(ref) - return owner && owner !== scope && owner !== analyzed.scope - }) + const bindVars = getBindVars(node, scopeTree) let newParams = [ ...bindVars, ...node.params.map((n) => input.slice(n.start, n.end)), @@ -190,3 +167,15 @@ export function findDirectives(ast: Program, directive: string): Literal[] { }) return nodes } + +function getBindVars(fn: Node, scopeTree: ScopeTree): string[] { + const fnScope = scopeTree.nodeScope.get(fn)! + const ancestorScopes = fnScope.getAncestorScopes() + const references = scopeTree.scopeToReferences.get(fnScope) ?? [] + // bind variables that are the ones declared in ancestor scopes but not module global scope + const bindReferences = references.filter((id) => { + const scope = scopeTree.referenceToDeclaredScope.get(id) + return scope && scope !== scopeTree.moduleScope && ancestorScopes.has(scope) + }) + return [...new Set(bindReferences.map((id) => id.name))] +} diff --git a/packages/plugin-rsc/src/transforms/proxy-export.ts b/packages/plugin-rsc/src/transforms/proxy-export.ts index f08a05701..b382ef139 100644 --- a/packages/plugin-rsc/src/transforms/proxy-export.ts +++ b/packages/plugin-rsc/src/transforms/proxy-export.ts @@ -1,8 +1,7 @@ import { tinyassert } from '@hiogawa/utils' import type { Node, Program } from 'estree' import MagicString from 'magic-string' -import { extract_names } from 'periscopic' -import { hasDirective } from './utils' +import { extractNames, hasDirective } from './utils' export type TransformProxyExportOptions = { /** Required for source map and `keep` options */ @@ -112,7 +111,7 @@ export function transformProxyExport( } } const names = node.declaration.declarations.flatMap((decl) => - extract_names(decl.id), + extractNames(decl.id), ) createExport(node, names) } else { diff --git a/packages/plugin-rsc/src/transforms/scope.test.ts b/packages/plugin-rsc/src/transforms/scope.test.ts new file mode 100644 index 000000000..7207772d5 --- /dev/null +++ b/packages/plugin-rsc/src/transforms/scope.test.ts @@ -0,0 +1,137 @@ +import path from 'node:path' +import type { Identifier, Node } from 'estree' +import { parseAstAsync } from 'vite' +import { describe, expect, it } from 'vitest' +import { type Scope, type ScopeTree, buildScopeTree } from './scope' + +// TODO: +// - use single markdown as snaphsot? (cf. review-scope-fixtures.ts) + +describe('fixtures', () => { + const fixtures = import.meta.glob('./fixtures/scope/**/*.js', { + query: 'raw', + }) + for (const [file, mod] of Object.entries(fixtures)) { + it(path.basename(file), async () => { + const input = ((await mod()) as any).default as string + const ast = await parseAstAsync(input) + const scopeTree = buildScopeTree(ast) + const serialized = serializeScopeTree(scopeTree) + await expect( + JSON.stringify(serialized, null, 2) + '\n', + ).toMatchFileSnapshot(file + '.snap.json') + }) + } +}) + +// ── Serializer ──────────────────────────────────────────────────────────────── + +type SerializedScope = { + type: string + declarations: string[] + references: { name: string; declaredAt: string | null }[] + children: SerializedScope[] +} + +function serializeScopeTree(scopeTree: ScopeTree): SerializedScope { + const { + nodeScope, + referenceToDeclaredScope, + scopeToReferences, + moduleScope, + } = scopeTree + + // Build scope → label and scope → direct children. + // Labels are disambiguated per parent (e.g. BlockStatement[2] for the second sibling). + const scopeLabelMap = new Map() + const scopeChildrenMap = new DefaultMap(() => []) + const siblingCount = new DefaultMap>( + () => new DefaultMap(() => 0), + ) + + for (const [node, scope] of nodeScope.entries()) { + const base = toScopeNodeLabel(node) + scopeLabelMap.set(scope, base) + scopeChildrenMap.set(scope, []) + if (!scope.parent) { + continue + } + const parent = scope.parent + const counts = siblingCount.get(parent) + const n = counts.get(base) + 1 + counts.set(base, n) + scopeLabelMap.set(scope, n === 1 ? base : `${base}[${n}]`) + scopeChildrenMap.get(parent).push(scope) + } + + // Direct references for a scope = all propagated refs minus those in child scopes. + function getDirectReferences(scope: Scope) { + const allRefs = scopeToReferences.get(scope) ?? [] + const childRefSet = new Set( + scopeChildrenMap + .get(scope) + .flatMap((c) => scopeToReferences.get(c) ?? []), + ) + return allRefs.filter((id) => !childRefSet.has(id)) + } + + function serializeDeclaredPath(id: Identifier): string | null { + const declScope = referenceToDeclaredScope.get(id) + if (!declScope) { + return null + } + const scopes = [declScope, ...declScope.getAncestorScopes()].reverse() + return scopes.map((s) => scopeLabelMap.get(s)!).join(' > ') + } + + function serializeScope(scope: Scope): SerializedScope { + return { + type: scopeLabelMap.get(scope)!, + declarations: [...scope.declarations].sort(), + references: getDirectReferences(scope).map((id) => ({ + name: id.name, + declaredAt: serializeDeclaredPath(id), + })), + children: scopeChildrenMap + .get(scope)! + .map((child) => serializeScope(child)), + } + } + + return serializeScope(moduleScope) +} + +function toScopeNodeLabel(node: Node): string { + switch (node.type) { + case 'FunctionDeclaration': + // ESTree typing says `id` is present here, but the parser can still produce + // `export default function () {}` as a FunctionDeclaration with `id: null`. + return node.type + (node.id ? `:${node.id.name}` : '') + case 'FunctionExpression': + return node.type + (node.id ? `:${node.id.name}` : '') + case 'ClassDeclaration': + return node.type + (node.id ? `:${node.id.name}` : '') + case 'ClassExpression': + return node.type + (node.id ? `:${node.id.name}` : '') + case 'ArrowFunctionExpression': + return 'ArrowFunction' + default: + return node.type + } +} + +class DefaultMap extends Map { + constructor(private readonly init: (key: K) => V) { + super() + } + + override get(key: K): V { + let value = super.get(key) + if (value !== undefined) { + return value + } + value = this.init(key) + this.set(key, value) + return value + } +} diff --git a/packages/plugin-rsc/src/transforms/scope.ts b/packages/plugin-rsc/src/transforms/scope.ts new file mode 100644 index 000000000..9f57de21d --- /dev/null +++ b/packages/plugin-rsc/src/transforms/scope.ts @@ -0,0 +1,351 @@ +import type { + Program, + Identifier, + Node, + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, +} from 'estree' +import { walk } from 'estree-walker' +import { extractNames } from './utils' + +// Replacement for periscopic to correctly handle variable shadowing + +export class Scope { + readonly declarations: Set = new Set() + + constructor( + public readonly parent: Scope | undefined, + private readonly isFunction: boolean, + ) {} + + getNearestFunctionScope(): Scope { + return this.isFunction ? this : this.parent!.getNearestFunctionScope() + } + + getAncestorScopes(): Set { + const ancestors = new Set() + let curr = this.parent + while (curr) { + ancestors.add(curr) + curr = curr.parent + } + return ancestors + } +} + +export type ScopeTree = { + // each reference Identifier → the Scope that declared it (absent = undeclared i.e. assume global) + readonly referenceToDeclaredScope: Map + // each function Scope → reference Identifiers accessed within its scope + readonly scopeToReferences: Map + // scope-creating AST node → its Scope + readonly nodeScope: Map + readonly moduleScope: Scope +} + +export function buildScopeTree(ast: Program): ScopeTree { + const moduleScope = new Scope(undefined, true) + const nodeScope = new Map() + + // Inline resolution during the walk is wrong for `var`/function hoisting: a + // reference that appears before its `var` declaration would resolve to an outer + // binding rather than the locally-hoisted one. The fix is to defer resolution + // until after the walk, when all declarations are in the chain. We collect + // `{ id, visitScope }` pairs during the walk, then resolve them in a post-walk + // loop by scanning up from `visitScope` — at that point the scope tree is + // complete and the scan sees the correct picture. + + // ── Walk: collect declarations and raw reference pairs ─────────────────── + let current = moduleScope + nodeScope.set(ast, moduleScope) + + const rawReferences: Array<{ id: Identifier; visitScope: Scope }> = [] + const ancestors: Node[] = [] + + walk(ast, { + enter(node) { + ancestors.push(node) + if (node.type === 'ImportDeclaration') { + for (const spec of node.specifiers) { + current.declarations.add(spec.local.name) + } + } else if (isFunctionNode(node)) { + // Declare the function name in the current scope (block or function). + // In strict mode (ES modules), block-level function declarations are block-scoped. + if (node.type === 'FunctionDeclaration' && node.id) { + current.declarations.add(node.id.name) + } + // Param scope is separate from the body scope (BlockStatement below creates its own). + // This matches the JS spec: params have their own environment, the body has another. + const scope = new Scope(current, true) + nodeScope.set(node, scope) + current = scope + for (const param of node.params) { + for (const name of extractNames(param)) { + scope.declarations.add(name) + } + } + if (node.type === 'FunctionExpression' && node.id) { + scope.declarations.add(node.id.name) + } + } else if (node.type === 'ClassDeclaration' && node.id) { + current.declarations.add(node.id.name) + } else if (node.type === 'ClassExpression' && node.id) { + // Named class expressions have an inner self-binding visible from the + // heritage clause and the class body, similar to named function expressions. + const scope = new Scope(current, false) + scope.declarations.add(node.id.name) + nodeScope.set(node, scope) + current = scope + } else if ( + node.type === 'ForStatement' || + node.type === 'ForInStatement' || + node.type === 'ForOfStatement' || + node.type === 'SwitchStatement' || + node.type === 'BlockStatement' + ) { + const scope = new Scope(current, false) + nodeScope.set(node, scope) + current = scope + } else if (node.type === 'CatchClause') { + const scope = new Scope(current, false) + nodeScope.set(node, scope) + current = scope + if (node.param) { + for (const name of extractNames(node.param)) { + scope.declarations.add(name) + } + } + } else if (node.type === 'VariableDeclaration') { + const target = + node.kind === 'var' ? current.getNearestFunctionScope() : current + for (const decl of node.declarations) { + for (const name of extractNames(decl.id)) { + target.declarations.add(name) + } + } + } + // Collect reference identifiers for post-walk resolution. + // TODO: + // To extend to member-expression binding: instead of collecting just the + // Identifier, collect the outermost non-computed MemberExpression rooted at + // it (e.g. `x.y` in `x.y.z`) when one exists. The root + // Identifier is still used for `referenceToDeclaredScope`; the full node + // (Identifier | MemberExpression) goes into `scopeToReferences`. Then + // `getBindVars` inspects each entry — if it is a MemberExpression, extract + // the path key for binding instead of the bare name. + if ( + node.type === 'Identifier' && + isReferenceIdentifier(node, ancestors.slice(0, -1).reverse()) + ) { + rawReferences.push({ id: node, visitScope: current }) + } + }, + leave(node) { + ancestors.pop() + const scope = nodeScope.get(node) + if (scope?.parent) { + current = scope.parent + } + }, + }) + + // ── Post-walk fixup: resolve references against the complete scope tree ── + const scopeToReferences = new Map( + [...nodeScope.values()].map((scope) => [scope, []]), + ) + const referenceToDeclaredScope = new Map() + + for (const { id, visitScope } of rawReferences) { + // TODO: default param expressions should not resolve to `var` declarations + // from the same function body. We currently start lookup at `visitScope`, + // so `function f(x = y) { var y }` incorrectly resolves `y` to `f`'s own + // function scope instead of continuing to the parent scope. + let declScope: Scope | undefined = visitScope + while (declScope && !declScope.declarations.has(id.name)) { + declScope = declScope.parent + } + if (declScope) { + referenceToDeclaredScope.set(id, declScope) + } + // Propagate reference up through all ancestor scopes + let scope: Scope | undefined = visitScope + while (scope) { + scopeToReferences.get(scope)!.push(id) + scope = scope.parent + } + } + + return { + referenceToDeclaredScope, + scopeToReferences, + nodeScope, + moduleScope, + } +} + +type AnyFunctionNode = + | FunctionDeclaration + | FunctionExpression + | ArrowFunctionExpression + +function isFunctionNode(node: Node): node is AnyFunctionNode { + return ( + node.type === 'FunctionDeclaration' || + node.type === 'FunctionExpression' || + node.type === 'ArrowFunctionExpression' + ) +} + +// Positive reference classifier modeled after Vite SSR's `isRefIdentifier`, +// adapted for this ESTree-only scope walk. This is easier to audit than a +// negated binding check because many identifier positions are syntax-only names +// rather than bindings or references. +function isReferenceIdentifier(node: Identifier, parentStack: Node[]): boolean { + const parent = parentStack[0] + if (!parent) return true + + // declaration id + // disregard the `x` in `let x = y`, `class X {}`, or `catch (x) {}` + if ( + parent.type === 'CatchClause' || + ((parent.type === 'VariableDeclarator' || + parent.type === 'ClassDeclaration' || + parent.type === 'ClassExpression') && + parent.id === node) + ) { + return false + } + + if (isFunctionNode(parent)) { + // function declaration/expression id + // disregard the `f` in `function f() {}` or `(function f() {})` + if ('id' in parent && parent.id === node) { + return false + } + + // params list + // disregard the `x` in `function f(x) {}` + if (parent.params.includes(node)) { + return false + } + } + + // property key / class method / class field name + // disregard the `foo` in `{ foo: bar }`, `class { foo() {} }` or `class { foo = bar }`, + // but keep it in `{ [foo]: bar }``, `class { [foo]() {} }` or `class { [foo] = bar }`. + if ( + (parent.type === 'MethodDefinition' || + parent.type === 'PropertyDefinition' || + parent.type === 'Property') && + parent.key === node && + !parent.computed + ) { + return false + } + + // member expression property + // disregard the `bar` in `foo.bar`, but keep it in `foo[bar]` + if ( + parent.type === 'MemberExpression' && + parent.property === node && + !parent.computed + ) { + return false + } + + // meta property + // disregard the `import`/`meta` in `import.meta` + if (parent.type === 'MetaProperty') { + return false + } + + // Unlike Vite SSR, this walk does not pre-mark pattern nodes in a WeakSet, + // so we use the ESTree parent stack directly to recognize object patterns. + // disregard the `bar` in `const { foo: bar } = obj`, but keep it as a + // reference in `({ foo: bar } = obj)` + if ( + parent.type === 'Property' && + parent.value === node && + parentStack[1]?.type === 'ObjectPattern' + ) { + return isInDestructuringAssignment(parentStack) + } + + // array destructuring pattern + // disregard the `x` in `const [x] = value`, but keep it as a reference in + // `([x] = value)` + if (parent.type === 'ArrayPattern') { + return isInDestructuringAssignment(parentStack) + } + + // Unlike Vite SSR, this walk sees rest-pattern identifiers directly here. + // disregard the `rest` in declarations or params, but keep it as a reference + // in `({ ...rest } = value)` or `([...rest] = value)` + if (parent.type === 'RestElement' && parent.argument === node) { + return isInDestructuringAssignment(parentStack) + } + + // Unlike Vite SSR, this walk classifies pattern/default nodes here instead of + // relying on `handlePattern`, `setIsNodeInPattern`, and the separate param + // traversal to classify them during traversal. + // disregard the `x` in `function f(x = y) {}` or `const { x = y } = obj`, + // but keep it as a reference in `({ x = y } = obj)` or `([x = y] = arr)` + if (parent.type === 'AssignmentPattern' && parent.left === node) { + return isInDestructuringAssignment(parentStack) + } + + // Unlike Vite SSR, this walk does not skip ImportDeclaration up front, so + // import specifier syntax has to be filtered here as well. + // import/export specifier syntax names + // disregard the `foo`/`bar` in `import foo from 'x'`, `import * as foo from 'x'`, + // or `import { foo as bar } from 'x'` + if ( + parent.type === 'ImportSpecifier' || + parent.type === 'ImportDefaultSpecifier' || + parent.type === 'ImportNamespaceSpecifier' + ) { + return false + } + + // disregard the `bar` in `export { foo as bar }`, but keep the local `foo` + if (parent.type === 'ExportSpecifier') { + return parent.local === node + } + + // Explicitly handled here because these labels showed up as false positives in + // the scope fixtures; Vite SSR's helper does not need this branch. + // label identifiers + // disregard the `label` in `label: for (;;) {}`, `break label`, or + // `continue label` + if ( + parent.type === 'LabeledStatement' || + parent.type === 'BreakStatement' || + parent.type === 'ContinueStatement' + ) { + return false + } + + return true +} + +function isInDestructuringAssignment(parentStack: Node[]): boolean { + // `ObjectPattern` / `ArrayPattern` alone is ambiguous: the same immediate + // parent shape appears in declarations, params, and assignment targets. + // + // Treat as references: + // - `x` in `[x] = value` + // - `x` in `({ x } = value)` + // - `x` in `({ a: [x] } = value)` + // + // Do not treat as references: + // - `x` in `const [x] = value` + // - `x` in `const { x } = value` + // - `x` in `function f([x]) {}` + // - `x` in `function f({ x }) {}` + // + // The distinction only appears higher in the ancestor chain, where assignment + // targets are owned by an `AssignmentExpression`. + return parentStack.some((node) => node.type === 'AssignmentExpression') +} diff --git a/packages/plugin-rsc/src/transforms/utils.ts b/packages/plugin-rsc/src/transforms/utils.ts index aafcecbfc..7230d4a34 100644 --- a/packages/plugin-rsc/src/transforms/utils.ts +++ b/packages/plugin-rsc/src/transforms/utils.ts @@ -1,6 +1,5 @@ import { tinyassert } from '@hiogawa/utils' -import type { Program } from 'estree' -import { extract_names } from 'periscopic' +import type { Identifier, Pattern, Program } from 'estree' export function hasDirective( body: Program['body'], @@ -41,7 +40,7 @@ export function getExportNames( * export const foo = 1, bar = 2 */ for (const decl of node.declaration.declarations) { - exportNames.push(...extract_names(decl.id)) + exportNames.push(...extractNames(decl.id)) } } else { node.declaration satisfies never @@ -80,3 +79,60 @@ export function getExportNames( return { exportNames } } + +// Copied from periscopic `extract_names` / `extract_identifiers` +export function extractNames(param: Pattern): string[] { + return extractIdentifiers(param).map((n) => n.name) +} + +// Copied from periscopic and intentionally broader than this repo's current +// declaration-oriented use cases. +// +// ESTree's `Pattern` type also covers assignment targets, where +// `MemberExpression` can appear (for example `({ x: obj.y } = value)`), so this +// helper preserves periscopic's behavior of reducing `a.b.c` to the base +// identifier `a`. +// +// In this repo, current callers use it only for declaration/binding positions +// (`VariableDeclarator.id`, function params, catch params), where +// `MemberExpression` should not appear for valid input. That branch is kept for +// compatibility with the original helper rather than because current +// declaration use cases require it. +export function extractIdentifiers( + param: Pattern, + nodes: Identifier[] = [], +): Identifier[] { + switch (param.type) { + case 'Identifier': + nodes.push(param) + break + case 'MemberExpression': { + let obj = param as any + while (obj.type === 'MemberExpression') { + obj = obj.object + } + nodes.push(obj) + break + } + case 'ObjectPattern': + for (const prop of param.properties) { + extractIdentifiers( + prop.type === 'RestElement' ? prop : prop.value, + nodes, + ) + } + break + case 'ArrayPattern': + for (const el of param.elements) { + if (el) extractIdentifiers(el, nodes) + } + break + case 'RestElement': + extractIdentifiers(param.argument, nodes) + break + case 'AssignmentPattern': + extractIdentifiers(param.left, nodes) + break + } + return nodes +} diff --git a/packages/plugin-rsc/src/transforms/wrap-export.ts b/packages/plugin-rsc/src/transforms/wrap-export.ts index 5c6cdcae4..a8b18f20c 100644 --- a/packages/plugin-rsc/src/transforms/wrap-export.ts +++ b/packages/plugin-rsc/src/transforms/wrap-export.ts @@ -1,7 +1,7 @@ import { tinyassert } from '@hiogawa/utils' import type { Node, Program } from 'estree' import MagicString from 'magic-string' -import { extract_names } from 'periscopic' +import { extractNames } from './utils' type ExportMeta = { declName?: string @@ -131,7 +131,7 @@ export function transformWrapExport( ) } const names = node.declaration.declarations.flatMap((decl) => - extract_names(decl.id), + extractNames(decl.id), ) // treat only simple single decl as function let isFunction = false diff --git a/packages/plugin-rsc/tsconfig.json b/packages/plugin-rsc/tsconfig.json index e4cfe71d1..17f837694 100644 --- a/packages/plugin-rsc/tsconfig.json +++ b/packages/plugin-rsc/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "./tsconfig.base.json", - "include": ["src", "*.ts", "types"], + "include": ["src", "*.ts", "types", "scripts"], "compilerOptions": { "noPropertyAccessFromIndexSignature": false, "noImplicitReturns": false, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2431ccd8..8c97d5058 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -442,9 +442,6 @@ importers: magic-string: specifier: ^0.30.21 version: 0.30.21 - periscopic: - specifier: ^4.0.2 - version: 4.0.2 srvx: specifier: ^0.11.13 version: 0.11.13 @@ -3989,9 +3986,6 @@ packages: periscopic@3.1.0: resolution: {integrity: sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==} - periscopic@4.0.2: - resolution: {integrity: sha512-sqpQDUy8vgB7ycLkendSKS6HnVz1Rneoc3Rc+ZBUCe2pbqlVuCC5vF52l0NJ1aiMg/r1qfYF9/myz8CZeI2rjA==} - picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -4815,9 +4809,6 @@ packages: youch@4.1.0-beta.10: resolution: {integrity: sha512-rLfVLB4FgQneDr0dv1oddCVZmKjcJ6yX6mS4pU82Mq/Dt9a3cLZQ62pDBL4AUO+uVrCvtWz3ZFUL2HFAFJ/BXQ==} - zimmerframe@1.1.2: - resolution: {integrity: sha512-rAbqEGa8ovJy4pyBxZM70hg4pE6gDgaQ0Sl9M3enG3I0d6H4XSAM3GeNGLKnsBpuijUow064sf7ww1nutC5/3w==} - zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} @@ -7628,12 +7619,6 @@ snapshots: estree-walker: 3.0.3 is-reference: 3.0.2 - periscopic@4.0.2: - dependencies: - '@types/estree': 1.0.8 - is-reference: 3.0.2 - zimmerframe: 1.1.2 - picocolors@1.1.1: {} picomatch@4.0.3: {} @@ -8427,6 +8412,4 @@ snapshots: cookie: 1.0.2 youch-core: 0.3.3 - zimmerframe@1.1.2: {} - zwitch@2.0.4: {}