Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ Official Rolldown plugins

## Packages

### Plugin Packages

- [`@rolldown/plugin-babel`](https://github.com/rolldown/plugins/tree/main/packages/babel) ([![NPM version][badge-npm-version-babel]][url-npm-babel]): transform code with Babel
- [`@rolldown/plugin-emotion`](https://github.com/rolldown/plugins/tree/main/packages/emotion) ([![NPM version][badge-npm-version-emotion]][url-npm-emotion]): minification and optimization of Emotion styles
- [`@rolldown/plugin-jsx-remove-attributes`](https://github.com/rolldown/plugins/tree/main/packages/jsx-remove-attributes) ([![NPM version][badge-npm-version-jsx-remove-attributes]][url-npm-jsx-remove-attributes]): remove JSX attributes (e.g. data-testid)

### Other Packages

- [`oxc-unshadowed-visitor`](https://github.com/rolldown/plugins/tree/main/packages/oxc-unshadowed-visitor): scope-aware AST visitor that tracks references to specified names, filtering out those shadowed by local bindings

## License

[MIT](https://github.com/rolldown/plugins/blob/main/LICENSE)
Expand Down
32 changes: 0 additions & 32 deletions internal-packages/oxc-unshadowed-visitor/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions internal-packages/oxc-unshadowed-visitor/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rolldown-string": "^0.3.0"
},
"devDependencies": {
"@rolldown/oxc-unshadowed-visitor": "workspace:*",
"oxc-unshadowed-visitor": "workspace:*",
"rolldown": "^1.0.0-rc.10",
"tinyglobby": "^0.2.15",
"vite": "^8.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withMagicString } from 'rolldown-string'
import type { Plugin } from 'rolldown'
import type { ESTree } from 'rolldown/utils'
import { ScopedVisitor } from '@rolldown/oxc-unshadowed-visitor'
import { ScopedVisitor } from 'oxc-unshadowed-visitor'
import type { EmotionPluginOptions } from './types.js'
import { minifyCSSString } from './css-minify.js'
import { createSourceMap, getPos } from './source-map.js'
Expand Down
65 changes: 65 additions & 0 deletions packages/oxc-unshadowed-visitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# oxc-unshadowed-visitor [![npm](https://img.shields.io/npm/v/oxc-unshadowed-visitor.svg)](https://npmx.dev/package/oxc-unshadowed-visitor)

Scope-aware AST visitor that tracks references to specified names, filtering out those shadowed by local bindings. Performs single-pass analysis using Rolldown's built-in AST visitor.

## Install

```bash
pnpm add -D oxc-unshadowed-visitor
```

## Usage

```ts
import { parseSync } from 'rolldown/utils'
import { ScopedVisitor } from 'oxc-unshadowed-visitor'

const program = parseSync('app.tsx', code).program

const sv = new ScopedVisitor<string>({
trackedNames: ['React'],
visitor: {
Identifier(node, ctx) {
if (node.name === 'React') {
ctx.record({ name: node.name, node, data: 'jsx-ref' })
}
},
},
})

const records = sv.walk(program)
// records contains only references where `React` is NOT shadowed
```

## API

### `ScopedVisitor<T>`

Main class that walks the AST once and maintains a scope stack internally. When your visitor calls `ctx.record()`, the record is kept only if the tracked name is not shadowed at that point. If a later `var` declaration hoists into scope, previously recorded references are retroactively invalidated.

#### `new ScopedVisitor(options)`

- **`options.trackedNames`** — `string[]` — Names to track for shadowing.
- **`options.visitor`** — `ScopedVisitorObject<T>` — Visitor object with handlers that receive the AST node and a `VisitorContext<T>`.

#### `sv.walk(program): TransformRecord<T>[]`

Walks the given `ESTree.Program` and returns an array of records that were not shadowed.

### `VisitorContext<T>`

- **`record(opts: { name: string; node: object; data: T })`** — Records a reference. The record is automatically filtered out if the name is shadowed at the call site.

### `TransformRecord<T>`

```ts
interface TransformRecord<T> {
name: string
node: object
data: T
}
```

## License

MIT
44 changes: 44 additions & 0 deletions packages/oxc-unshadowed-visitor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "oxc-unshadowed-visitor",
"version": "0.0.0",
"description": "Scope-aware AST visitor that filters out references shadowed by local bindings",
"keywords": [
"ast",
"oxc",
"rolldown",
"scope",
"visitor"
],
"homepage": "https://github.com/rolldown/plugins/tree/main/packages/oxc-unshadowed-visitor#readme",
"bugs": {
"url": "https://github.com/rolldown/plugins/issues"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/rolldown/plugins.git",
"directory": "packages/oxc-unshadowed-visitor"
},
"files": [
"dist"
],
"type": "module",
"exports": "./dist/index.mjs",
"scripts": {
"dev": "tsdown --watch",
"build": "tsdown",
"bench": "vitest bench --project oxc-unshadowed-visitor",
"test": "vitest --project oxc-unshadowed-visitor",
"prepublishOnly": "pnpm run build"
},
"devDependencies": {
"oxc-walker": "^0.7.0",
"rolldown": "^1.0.0-rc.10"
},
"peerDependencies": {
"rolldown": "^1.0.0-rc.9"
},
"engines": {
"node": ">=22.12.0 || ^24.0.0"
}
}
9 changes: 9 additions & 0 deletions packages/oxc-unshadowed-visitor/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsdown'

export default defineConfig({
entry: './src/index.ts',
dts: {
tsconfig: '../../tsconfig.common.json',
tsgo: true,
},
})
23 changes: 11 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.