-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve types for visitor exports
- Loading branch information
1 parent
54bd279
commit 719d8a1
Showing
28 changed files
with
143 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marko/translator-tags": patch | ||
--- | ||
|
||
XML Declarations are now a compile error (like cdata). |
7 changes: 7 additions & 0 deletions
7
...tor-tags/src/__tests__/fixtures/declaration/__snapshots__/dom.expected/template.error.txt
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,7 @@ | ||
|
||
at packages/translator-tags/src/__tests__/fixtures/declaration/template.marko:1:1 | ||
> 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ XML declarations sections are not supported in Marko. | ||
2 | <contact-info> | ||
3 | <name>Hello World</name> | ||
4 | </contact-info> |
5 changes: 0 additions & 5 deletions
5
...translator-tags/src/__tests__/fixtures/declaration/__snapshots__/dom.expected/template.js
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...or-tags/src/__tests__/fixtures/declaration/__snapshots__/html.expected/template.error.txt
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,7 @@ | ||
|
||
at packages/translator-tags/src/__tests__/fixtures/declaration/template.marko:1:1 | ||
> 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ XML declarations sections are not supported in Marko. | ||
2 | <contact-info> | ||
3 | <name>Hello World</name> | ||
4 | </contact-info> |
6 changes: 0 additions & 6 deletions
6
...ranslator-tags/src/__tests__/fixtures/declaration/__snapshots__/html.expected/template.js
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
packages/translator-tags/src/__tests__/fixtures/declaration/test.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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export const skip_csr = true; | ||
export const skip_ssr = true; | ||
export const error_compiler = true; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { types as t } from "@marko/compiler"; | ||
|
||
export type VisitorType = "migrate" | "transform" | "analyze" | "translate"; | ||
export type TemplateVisitor<T extends t.Node> = Partial< | ||
Record<VisitorType, t.VisitNode<unknown, T>> | ||
>; | ||
|
||
export function extractVisitors< | ||
Visitors extends Partial<Record<keyof t.Visitor, TemplateVisitor<any>>>, | ||
>(visitors: Visitors) { | ||
const result: Record<VisitorType, t.Visitor> = { | ||
migrate: {}, | ||
transform: {}, | ||
analyze: {}, | ||
translate: {}, | ||
}; | ||
|
||
for (const _name in visitors) { | ||
const name = _name as any; | ||
const value = visitors[name]!; | ||
if (value.migrate) result.migrate[name] = value.migrate; | ||
if (value.transform) result.transform[name] = value.transform; | ||
if (value.analyze) result.analyze[name] = value.analyze; | ||
if (value.translate) result.translate[name] = value.translate; | ||
} | ||
return result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import type { types as t } from "@marko/compiler"; | ||
|
||
import type { TemplateVisitor } from "../util/visitors"; | ||
|
||
export default { | ||
translate: { | ||
enter(path: t.NodePath<t.MarkoCDATA>) { | ||
throw path.buildCodeFrameError( | ||
enter(cdata) { | ||
throw cdata.buildCodeFrameError( | ||
"CDATA sections are not supported in Marko.", | ||
); | ||
}, | ||
}, | ||
}; | ||
} satisfies TemplateVisitor<t.MarkoCDATA>; |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import type { types as t } from "@marko/compiler"; | ||
|
||
import type { TemplateVisitor } from "../util/visitors"; | ||
|
||
export default { | ||
translate: { | ||
exit(comment: t.NodePath<t.MarkoComment>) { | ||
exit(comment) { | ||
comment.remove(); | ||
}, | ||
}, | ||
}; | ||
} satisfies TemplateVisitor<t.MarkoComment>; |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import type { types as t } from "@marko/compiler"; | ||
|
||
import { isOutputHTML } from "../util/marko-config"; | ||
import * as writer from "../util/writer"; | ||
import type { TemplateVisitor } from "../util/visitors"; | ||
|
||
export default { | ||
translate: { | ||
exit(declaration: t.NodePath<t.MarkoDeclaration>) { | ||
if (isOutputHTML()) { | ||
writer.writeTo(declaration)`<?${declaration.node.value}?>`; | ||
} | ||
|
||
declaration.remove(); | ||
enter(decl) { | ||
throw decl.buildCodeFrameError( | ||
"XML declarations sections are not supported in Marko.", | ||
); | ||
}, | ||
}, | ||
}; | ||
} satisfies TemplateVisitor<t.MarkoDeclaration>; |
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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import type { types as t } from "@marko/compiler"; | ||
|
||
import { isOutputHTML } from "../util/marko-config"; | ||
import type { TemplateVisitor } from "../util/visitors"; | ||
import * as writer from "../util/writer"; | ||
|
||
export default { | ||
translate: { | ||
exit(documentType: t.NodePath<t.MarkoDocumentType>) { | ||
exit(documentType) { | ||
if (isOutputHTML()) { | ||
writer.writeTo(documentType)`<!${documentType.node.value}>`; | ||
} | ||
documentType.remove(); | ||
}, | ||
}, | ||
}; | ||
} satisfies TemplateVisitor<t.MarkoDocumentType>; |
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
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
Oops, something went wrong.