summaryrefslogtreecommitdiff
path: root/src/ast.ts
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-03-31 16:46:09 -0400
committerGravatar GitHub <noreply@github.com> 2021-03-31 16:46:09 -0400
commitd5b15a385153915cad7dbffd0d8893c39059c1ed (patch)
tree769240e3f6e52c31639f0500d97b87e45f202a6a /src/ast.ts
parentd9084ff4ad9e25577846d3eb53046c2f0066097f (diff)
downloadastro-d5b15a385153915cad7dbffd0d8893c39059c1ed.tar.gz
astro-d5b15a385153915cad7dbffd0d8893c39059c1ed.tar.zst
astro-d5b15a385153915cad7dbffd0d8893c39059c1ed.zip
Support for custom elements (#45)
* Support for custom elements Now you can use custom elements like so in Astro components: ```html <script type="module" src="./datepicker.js"> <date-picker></date-picker> ``` These will be resolve relative to the current astro component. In the build these modules are run through the same bundle/minify process as components. * Remove component from public * Formatting * Disable empty fn rule
Diffstat (limited to 'src/ast.ts')
-rw-r--r--src/ast.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ast.ts b/src/ast.ts
new file mode 100644
index 000000000..6c0bd7bd2
--- /dev/null
+++ b/src/ast.ts
@@ -0,0 +1,23 @@
+import type { Attribute } from './parser/interfaces';
+
+// AST utility functions
+
+export function getAttr(attributes: Attribute[], name: string): Attribute | undefined {
+ const attr = attributes.find((a) => a.name === name);
+ return attr;
+}
+
+export function getAttrValue(attributes: Attribute[], name: string): string | undefined {
+ const attr = getAttr(attributes, name);
+ if (attr) {
+ return attr.value[0]?.data;
+ }
+}
+
+export function setAttrValue(attributes: Attribute[], name: string, value: string): void {
+ const attr = attributes.find((a) => a.name === name);
+ if (attr) {
+ attr.value[0]!.data = value;
+ attr.value[0]!.raw = value;
+ }
+}