-
Notifications
You must be signed in to change notification settings - Fork 81
fix: allow conditional rendering when RenderScript is enabled
#1057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7857889
test: add test cases
MoustaphaDev 65e3444
fix: allow processing scripts in expressions when `RenderScript` is e…
MoustaphaDev fd8cb93
test: add test case without src attribute
MoustaphaDev 7e51d53
fix: add `nil` parent guard
MoustaphaDev 339179b
test: add new snapshots
MoustaphaDev 00c14ab
chore: changeset
MoustaphaDev 33cff51
test: remove duplicate snapshot
MoustaphaDev 3f1f082
apply sarah's changeset suggestion
MoustaphaDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| "@astrojs/compiler": patch | ||
| --- | ||
|
|
||
| Allows conditional rendering of scripts when `RenderScript` is enabled | ||
82 changes: 82 additions & 0 deletions
82
internal/printer/__printer_js__/script_external_in_expression__renderScript__false_.snap
This file contains hidden or 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,82 @@ | ||
|
|
||
| [TestPrinter/script_external_in_expression_(renderScript:_false) - 1] | ||
| ## Input | ||
|
|
||
| ``` | ||
| <main>{<script src="./hello.js"></script>} | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| ```js | ||
| import { | ||
| Fragment, | ||
| render as $$render, | ||
| createAstro as $$createAstro, | ||
| createComponent as $$createComponent, | ||
| renderComponent as $$renderComponent, | ||
| renderHead as $$renderHead, | ||
| maybeRenderHead as $$maybeRenderHead, | ||
| unescapeHTML as $$unescapeHTML, | ||
| renderSlot as $$renderSlot, | ||
| mergeSlots as $$mergeSlots, | ||
| addAttribute as $$addAttribute, | ||
| spreadAttributes as $$spreadAttributes, | ||
| defineStyleVars as $$defineStyleVars, | ||
| defineScriptVars as $$defineScriptVars, | ||
| renderTransition as $$renderTransition, | ||
| createTransitionScope as $$createTransitionScope, | ||
| renderScript as $$renderScript, | ||
| createMetadata as $$createMetadata | ||
| } from "http://localhost:3000/"; | ||
|
|
||
| export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
|
||
| const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
|
||
| return $$render`${$$maybeRenderHead($$result)}<main>${$$render`<script src="./hello.js"></script>`}</main>`; | ||
| }, '/src/pages/index.astro', undefined); | ||
| export default $$Index; | ||
| ``` | ||
| --- | ||
|
|
||
| [TestPrinter/script_external_in_expression_(renderScript:_false)#01 - 1] | ||
| ## Input | ||
|
|
||
| ``` | ||
| <main>{false && <script>console.log("hello")</script>} | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| ```js | ||
| import { | ||
| Fragment, | ||
| render as $$render, | ||
| createAstro as $$createAstro, | ||
| createComponent as $$createComponent, | ||
| renderComponent as $$renderComponent, | ||
| renderHead as $$renderHead, | ||
| maybeRenderHead as $$maybeRenderHead, | ||
| unescapeHTML as $$unescapeHTML, | ||
| renderSlot as $$renderSlot, | ||
| mergeSlots as $$mergeSlots, | ||
| addAttribute as $$addAttribute, | ||
| spreadAttributes as $$spreadAttributes, | ||
| defineStyleVars as $$defineStyleVars, | ||
| defineScriptVars as $$defineScriptVars, | ||
| renderTransition as $$renderTransition, | ||
| createTransitionScope as $$createTransitionScope, | ||
| renderScript as $$renderScript, | ||
| createMetadata as $$createMetadata | ||
| } from "http://localhost:3000/"; | ||
|
|
||
| export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
|
||
| const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
|
||
| return $$render`${$$maybeRenderHead($$result)}<main>${false && $$render`<script>console.log("hello")</script>`}</main>`; | ||
| }, '/src/pages/index.astro', undefined); | ||
| export default $$Index; | ||
| ``` | ||
| --- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_external_in_expression__renderScript__true_.snap
This file contains hidden or 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,41 @@ | ||
|
|
||
| [TestPrinter/script_external_in_expression_(renderScript:_true) - 1] | ||
| ## Input | ||
|
|
||
| ``` | ||
| <main>{<script src="./hello.js"></script>} | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| ```js | ||
| import { | ||
| Fragment, | ||
| render as $$render, | ||
| createAstro as $$createAstro, | ||
| createComponent as $$createComponent, | ||
| renderComponent as $$renderComponent, | ||
| renderHead as $$renderHead, | ||
| maybeRenderHead as $$maybeRenderHead, | ||
| unescapeHTML as $$unescapeHTML, | ||
| renderSlot as $$renderSlot, | ||
| mergeSlots as $$mergeSlots, | ||
| addAttribute as $$addAttribute, | ||
| spreadAttributes as $$spreadAttributes, | ||
| defineStyleVars as $$defineStyleVars, | ||
| defineScriptVars as $$defineScriptVars, | ||
| renderTransition as $$renderTransition, | ||
| createTransitionScope as $$createTransitionScope, | ||
| renderScript as $$renderScript, | ||
| createMetadata as $$createMetadata | ||
| } from "http://localhost:3000/"; | ||
|
|
||
| export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [{ type: 'external', src: './hello.js' }] }); | ||
|
|
||
| const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
|
||
| return $$render`${$$maybeRenderHead($$result)}<main>${$$render`${$$renderScript($$result,"/src/pages/index.astro?astro&type=script&index=0&lang.ts")}`}</main>`; | ||
| }, '/src/pages/index.astro', undefined); | ||
| export default $$Index; | ||
| ``` | ||
| --- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_in_expression__renderScript__false_.snap
This file contains hidden or 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,41 @@ | ||
|
|
||
| [TestPrinter/script_in_expression_(renderScript:_false) - 1] | ||
| ## Input | ||
|
|
||
| ``` | ||
| <main>{false && <script>console.log("hello")</script>} | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| ```js | ||
| import { | ||
| Fragment, | ||
| render as $$render, | ||
| createAstro as $$createAstro, | ||
| createComponent as $$createComponent, | ||
| renderComponent as $$renderComponent, | ||
| renderHead as $$renderHead, | ||
| maybeRenderHead as $$maybeRenderHead, | ||
| unescapeHTML as $$unescapeHTML, | ||
| renderSlot as $$renderSlot, | ||
| mergeSlots as $$mergeSlots, | ||
| addAttribute as $$addAttribute, | ||
| spreadAttributes as $$spreadAttributes, | ||
| defineStyleVars as $$defineStyleVars, | ||
| defineScriptVars as $$defineScriptVars, | ||
| renderTransition as $$renderTransition, | ||
| createTransitionScope as $$createTransitionScope, | ||
| renderScript as $$renderScript, | ||
| createMetadata as $$createMetadata | ||
| } from "http://localhost:3000/"; | ||
|
|
||
| export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] }); | ||
|
|
||
| const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
|
||
| return $$render`${$$maybeRenderHead($$result)}<main>${false && $$render`<script>console.log("hello")</script>`}</main>`; | ||
| }, '/src/pages/index.astro', undefined); | ||
| export default $$Index; | ||
| ``` | ||
| --- |
41 changes: 41 additions & 0 deletions
41
internal/printer/__printer_js__/script_in_expression__renderScript__true_.snap
This file contains hidden or 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,41 @@ | ||
|
|
||
| [TestPrinter/script_in_expression_(renderScript:_true) - 1] | ||
| ## Input | ||
|
|
||
| ``` | ||
| <main>{true && <script>console.log("hello")</script>} | ||
| ``` | ||
|
|
||
| ## Output | ||
|
|
||
| ```js | ||
| import { | ||
| Fragment, | ||
| render as $$render, | ||
| createAstro as $$createAstro, | ||
| createComponent as $$createComponent, | ||
| renderComponent as $$renderComponent, | ||
| renderHead as $$renderHead, | ||
| maybeRenderHead as $$maybeRenderHead, | ||
| unescapeHTML as $$unescapeHTML, | ||
| renderSlot as $$renderSlot, | ||
| mergeSlots as $$mergeSlots, | ||
| addAttribute as $$addAttribute, | ||
| spreadAttributes as $$spreadAttributes, | ||
| defineStyleVars as $$defineStyleVars, | ||
| defineScriptVars as $$defineScriptVars, | ||
| renderTransition as $$renderTransition, | ||
| createTransitionScope as $$createTransitionScope, | ||
| renderScript as $$renderScript, | ||
| createMetadata as $$createMetadata | ||
| } from "http://localhost:3000/"; | ||
|
|
||
| export const $$metadata = $$createMetadata("/src/pages/index.astro", { modules: [], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [{ type: 'inline', value: `console.log("hello")` }] }); | ||
|
|
||
| const $$Index = $$createComponent(($$result, $$props, $$slots) => { | ||
|
|
||
| return $$render`${$$maybeRenderHead($$result)}<main>${true && $$render`${$$renderScript($$result,"/src/pages/index.astro?astro&type=script&index=0&lang.ts")}`}</main>`; | ||
| }, '/src/pages/index.astro', undefined); | ||
| export default $$Index; | ||
| ``` | ||
| --- |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.