diff options
| author | akiyamn | 2023-09-24 23:22:21 +1000 |
|---|---|---|
| committer | akiyamn | 2023-09-24 23:22:21 +1000 |
| commit | 4e87195739f2a5d9a05451b48773c8afdc680765 (patch) | |
| tree | 9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/rollup-pluginutils/src/extractAssignedNames.ts | |
| download | price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip | |
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/rollup-pluginutils/src/extractAssignedNames.ts')
| -rw-r--r-- | node_modules/rollup-pluginutils/src/extractAssignedNames.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/node_modules/rollup-pluginutils/src/extractAssignedNames.ts b/node_modules/rollup-pluginutils/src/extractAssignedNames.ts new file mode 100644 index 0000000..996f41a --- /dev/null +++ b/node_modules/rollup-pluginutils/src/extractAssignedNames.ts @@ -0,0 +1,46 @@ +import { Node } from 'estree-walker'; + +interface Extractors { + [key: string]: (names: Array<string>, param: Node) => void; +} + +const extractors: Extractors = { + ArrayPattern(names: Array<string>, param: Node) { + for (const element of param.elements) { + if (element) extractors[element.type](names, element); + } + }, + + AssignmentPattern(names: Array<string>, param: Node) { + extractors[param.left.type](names, param.left); + }, + + Identifier(names: Array<string>, param: Node) { + names.push(param.name); + }, + + MemberExpression() {}, + + ObjectPattern(names: Array<string>, param: Node) { + for (const prop of param.properties) { + if (prop.type === 'RestElement') { + extractors.RestElement(names, prop); + } else { + extractors[prop.value.type](names, prop.value); + } + } + }, + + RestElement(names: Array<string>, param: Node) { + extractors[param.argument.type](names, param.argument); + } +}; + +const extractAssignedNames = function extractAssignedNames(param: Node): Array<string> { + const names: Array<string> = []; + + extractors[param.type](names, param); + return names; +}; + +export { extractAssignedNames as default }; |
