generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from storybookjs/post-transform-meta
refactor(transform)!: `meta` no longer destructurable from `defineMeta()` call
- Loading branch information
Showing
18 changed files
with
113 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
src/compiler/post-transform/appendix/create-export-default.test.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/compiler/post-transform/appendix/create-export-default.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
src/compiler/post-transform/define-meta/destructure-meta.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/compiler/post-transform/define-meta/replace-argument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createASTIdentifier, type ESTreeAST } from '../../../parser/ast'; | ||
import type { CompiledASTNodes } from '../../../parser/extract/compiled/nodes'; | ||
import type { SvelteASTNodes } from '../../../parser/extract/svelte/nodes'; | ||
import { getDefineMetaFirstArgumentObjectExpression } from '../../../parser/extract/svelte/define-meta'; | ||
import { NoDestructuredDefineMetaCallError } from '../../../utils/error/parser/analyse/define-meta'; | ||
|
||
interface Params { | ||
nodes: { | ||
compiled: CompiledASTNodes; | ||
svelte: SvelteASTNodes; | ||
}; | ||
filename?: string; | ||
} | ||
|
||
/** | ||
* Replaces `defineMeta({ ... })` with `defineMeta(meta)`, | ||
* and also it returns {@link ESTreeASTAST.ObjectExpression} which was replaced with {@link ESTreeAST.Identifier} | ||
*/ | ||
export function replaceDefineMetaArgument(params: Params): ESTreeAST.ObjectExpression { | ||
const defineMetaFirstArgumentObjectExpression = getDefineMetaFirstArgumentObjectExpression({ | ||
nodes: params.nodes.compiled, | ||
filename: params.filename, | ||
}); | ||
|
||
const declaration = params.nodes.compiled.defineMetaVariableDeclaration.declarations[0]; | ||
|
||
if ( | ||
!declaration || | ||
declaration.init?.type !== 'CallExpression' || | ||
declaration?.init?.callee.type !== 'Identifier' || | ||
declaration?.init?.callee.name !== params.nodes.compiled.defineMetaImport.local.name | ||
) { | ||
throw new NoDestructuredDefineMetaCallError({ | ||
defineMetaVariableDeclarator: declaration, | ||
filename: params.filename, | ||
}); | ||
} | ||
|
||
declaration.init.arguments[0] = createASTIdentifier('meta'); | ||
params.nodes.compiled.defineMetaVariableDeclaration.declarations[0] = declaration; | ||
|
||
return defineMetaFirstArgumentObjectExpression; | ||
} |
Oops, something went wrong.