From 907ab2303f4cf94265147dca780cd10b1c48df58 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Thu, 28 Oct 2021 08:25:39 -0700 Subject: [PATCH] fix: issue rendering attrs & return after a get --- package-lock.json | 5 ----- .../attrs-after-get/node.render.expected.html | 3 +++ .../attrs-after-get/web.render.expected.html | 3 +++ src/__tests__/fixtures/attrs/index.test.ts | 5 +++++ .../attrs/templates/after-get/components/provider.marko | 3 +++ .../attrs/templates/after-get/components/receiver.marko | 3 +++ .../fixtures/attrs/templates/after-get/index.marko | 3 +++ .../return-after-get/node.render.expected.html | 1 + .../return-after-get/web.render.expected.html | 1 + src/__tests__/fixtures/return/index.test.ts | 2 ++ .../return/templates/after-get/components/provider.marko | 3 +++ .../return/templates/after-get/components/receiver.marko | 3 +++ .../fixtures/return/templates/after-get/index.marko | 4 ++++ src/components/attrs/translate.ts | 3 ++- src/components/return/translate.ts | 3 ++- src/util/is-at-root.ts | 9 +++++++++ 16 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/node.render.expected.html create mode 100644 src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/web.render.expected.html create mode 100644 src/__tests__/fixtures/attrs/templates/after-get/components/provider.marko create mode 100644 src/__tests__/fixtures/attrs/templates/after-get/components/receiver.marko create mode 100644 src/__tests__/fixtures/attrs/templates/after-get/index.marko create mode 100644 src/__tests__/fixtures/return/__snapshots__/return-after-get/node.render.expected.html create mode 100644 src/__tests__/fixtures/return/__snapshots__/return-after-get/web.render.expected.html create mode 100644 src/__tests__/fixtures/return/templates/after-get/components/provider.marko create mode 100644 src/__tests__/fixtures/return/templates/after-get/components/receiver.marko create mode 100644 src/__tests__/fixtures/return/templates/after-get/index.marko create mode 100644 src/util/is-at-root.ts diff --git a/package-lock.json b/package-lock.json index 701cb92..c682a80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9057,11 +9057,6 @@ "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" }, - "bin": { - "sshpk-conv": "bin/sshpk-conv", - "sshpk-sign": "bin/sshpk-sign", - "sshpk-verify": "bin/sshpk-verify" - }, "engines": { "node": ">=0.10.0" } diff --git a/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/node.render.expected.html b/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/node.render.expected.html new file mode 100644 index 0000000..7919dbd --- /dev/null +++ b/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/node.render.expected.html @@ -0,0 +1,3 @@ +
+ Hello world +
\ No newline at end of file diff --git a/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/web.render.expected.html b/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/web.render.expected.html new file mode 100644 index 0000000..7919dbd --- /dev/null +++ b/src/__tests__/fixtures/attrs/__snapshots__/attrs-after-get/web.render.expected.html @@ -0,0 +1,3 @@ +
+ Hello world +
\ No newline at end of file diff --git a/src/__tests__/fixtures/attrs/index.test.ts b/src/__tests__/fixtures/attrs/index.test.ts index 265cec0..e7a7bd7 100644 --- a/src/__tests__/fixtures/attrs/index.test.ts +++ b/src/__tests__/fixtures/attrs/index.test.ts @@ -5,6 +5,11 @@ describe( fixture("./templates/basic.marko", { value: "World" }) ); +describe( + " after get", + fixture("./templates/after-get/index.marko", { value: "World" }) +); + describe( " error args", fixture("./templates/error-args.marko", { value: "World" }) diff --git a/src/__tests__/fixtures/attrs/templates/after-get/components/provider.marko b/src/__tests__/fixtures/attrs/templates/after-get/components/provider.marko new file mode 100644 index 0000000..63e0e82 --- /dev/null +++ b/src/__tests__/fixtures/attrs/templates/after-get/components/provider.marko @@ -0,0 +1,3 @@ + + <${input.renderBody}/> + diff --git a/src/__tests__/fixtures/attrs/templates/after-get/components/receiver.marko b/src/__tests__/fixtures/attrs/templates/after-get/components/receiver.marko new file mode 100644 index 0000000..aee7dcf --- /dev/null +++ b/src/__tests__/fixtures/attrs/templates/after-get/components/receiver.marko @@ -0,0 +1,3 @@ + + +
${data} ${value}
diff --git a/src/__tests__/fixtures/attrs/templates/after-get/index.marko b/src/__tests__/fixtures/attrs/templates/after-get/index.marko new file mode 100644 index 0000000..5e630e4 --- /dev/null +++ b/src/__tests__/fixtures/attrs/templates/after-get/index.marko @@ -0,0 +1,3 @@ + + + diff --git a/src/__tests__/fixtures/return/__snapshots__/return-after-get/node.render.expected.html b/src/__tests__/fixtures/return/__snapshots__/return-after-get/node.render.expected.html new file mode 100644 index 0000000..5bbb6e4 --- /dev/null +++ b/src/__tests__/fixtures/return/__snapshots__/return-after-get/node.render.expected.html @@ -0,0 +1 @@ + Hello world \ No newline at end of file diff --git a/src/__tests__/fixtures/return/__snapshots__/return-after-get/web.render.expected.html b/src/__tests__/fixtures/return/__snapshots__/return-after-get/web.render.expected.html new file mode 100644 index 0000000..5bbb6e4 --- /dev/null +++ b/src/__tests__/fixtures/return/__snapshots__/return-after-get/web.render.expected.html @@ -0,0 +1 @@ + Hello world \ No newline at end of file diff --git a/src/__tests__/fixtures/return/index.test.ts b/src/__tests__/fixtures/return/index.test.ts index fc4c0f6..7602cc6 100644 --- a/src/__tests__/fixtures/return/index.test.ts +++ b/src/__tests__/fixtures/return/index.test.ts @@ -2,6 +2,8 @@ import fixture, { FixtureHelpers } from "../../fixture"; describe(" basic", fixture("./templates/basic.marko")); +describe(" after get", fixture("./templates/after-get/index.marko")); + describe(" spread", fixture("./templates/spread.marko")); describe(" read multiple", fixture("./templates/read-multiple.marko")); diff --git a/src/__tests__/fixtures/return/templates/after-get/components/provider.marko b/src/__tests__/fixtures/return/templates/after-get/components/provider.marko new file mode 100644 index 0000000..a3731c5 --- /dev/null +++ b/src/__tests__/fixtures/return/templates/after-get/components/provider.marko @@ -0,0 +1,3 @@ + + <${input.renderBody}/> + diff --git a/src/__tests__/fixtures/return/templates/after-get/components/receiver.marko b/src/__tests__/fixtures/return/templates/after-get/components/receiver.marko new file mode 100644 index 0000000..1ccd5c3 --- /dev/null +++ b/src/__tests__/fixtures/return/templates/after-get/components/receiver.marko @@ -0,0 +1,3 @@ + + + diff --git a/src/__tests__/fixtures/return/templates/after-get/index.marko b/src/__tests__/fixtures/return/templates/after-get/index.marko new file mode 100644 index 0000000..b1b4200 --- /dev/null +++ b/src/__tests__/fixtures/return/templates/after-get/index.marko @@ -0,0 +1,4 @@ + + + Hello ${value} + diff --git a/src/components/attrs/translate.ts b/src/components/attrs/translate.ts index 6cc92d5..6fbeac3 100644 --- a/src/components/attrs/translate.ts +++ b/src/components/attrs/translate.ts @@ -1,5 +1,6 @@ import { types as t } from "@marko/compiler"; import deepFreeze from "../../util/deep-freeze/transform"; +import isAtRoot from "../../util/is-at-root"; const usedTag = new WeakSet(); export = (tag: t.NodePath) => { @@ -8,7 +9,7 @@ export = (tag: t.NodePath) => { ? "can only be used once within a template" : !tagVar ? "requires a tag variable to be assigned to" - : !tag.parentPath.parentPath!.isProgram() + : !isAtRoot(tag) ? "can only used at the root of the template" : tag.node.attributes.length > 0 ? "does not support attributes" diff --git a/src/components/return/translate.ts b/src/components/return/translate.ts index e31c429..617a46f 100644 --- a/src/components/return/translate.ts +++ b/src/components/return/translate.ts @@ -1,4 +1,5 @@ import { types as t } from "@marko/compiler"; +import isAtRoot from "../../util/is-at-root"; const usedTag = new WeakSet(); export = (tag: t.NodePath) => { @@ -6,7 +7,7 @@ export = (tag: t.NodePath) => { ? "can only be used once within a template" : tag.node.var ? "does not support a tag variable" - : !tag.parentPath.parentPath!.isProgram() + : !isAtRoot(tag) ? "can only used at the root of the template" : !tag.node.attributes.length ? "requires a default attribute" diff --git a/src/util/is-at-root.ts b/src/util/is-at-root.ts new file mode 100644 index 0000000..a7f1065 --- /dev/null +++ b/src/util/is-at-root.ts @@ -0,0 +1,9 @@ +import { types as t } from "@marko/compiler"; +import isCoreTag from "./is-core-tag"; + +export default function isAtRoot(tag: t.NodePath) { + const parentPath = tag.parentPath.parentPath!; + // Special case `` since it currently wraps it's children + // which is an implementation detail. + return parentPath!.isProgram() || isCoreTag("get", parentPath); +}