-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tell @marko/compiler about function event handlers
- Loading branch information
1 parent
f1ee0c9
commit 2fba2c9
Showing
3 changed files
with
34 additions
and
0 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/tags-api-preview": patch | ||
--- | ||
|
||
Use `meta.hasFunctionEventHandlers` from recent marko releases when we detect an event or change handler to ensure the template is marked for client side compilation.` |
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,25 @@ | ||
import { types as t } from "@marko/compiler"; | ||
import isApi from "../util/is-api"; | ||
const eventNameReg = /^on[A-Z]/; | ||
const changeNameReg = /Change$/; | ||
|
||
export default { | ||
MarkoTag(tag: t.NodePath<t.MarkoTag>) { | ||
if (isApi(tag, "tags")) { | ||
// Tells Marko that this tag uses event handlers. | ||
const file = tag.hub.file; | ||
const meta = file.metadata.marko as any; | ||
if (!meta.hasFunctionEventHandlers) { | ||
for (const attr of tag.node.attributes) { | ||
if ( | ||
t.isMarkoAttribute(attr) && | ||
(eventNameReg.test(attr.name) || changeNameReg.test(attr.name)) | ||
) { | ||
meta.hasFunctionEventHandlers = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
} as t.Visitor; |