Skip to content
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

fix: prevent printing defineVars() into an inline style #1001

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
cache: 'pnpm'

- name: Build WASM
run: make wasm
run: pnpm build

- name: Install NPM Dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
cache: 'pnpm'

- name: Build WASM
run: make wasm
run: pnpm build

- name: Install NPM Dependencies
run: pnpm install
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shell-emulator=true
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

3 changes: 3 additions & 0 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func (p *printer) printDefineVarsOpen(n *astro.Node) {
if !(n.DataAtom == atom.Script || n.DataAtom == atom.Style) {
return
}
if n.DataAtom == atom.Style && transform.HasAttr(n, "is:inline") {
return
}
if !transform.HasAttr(n, "define:vars") {
return
}
Expand Down
7 changes: 7 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,13 @@ const items = ["Dog", "Cat", "Platipus"];
definedVars: []string{"{color:'green'}"},
},
},
{
name: "style is:inline define:vars",
source: "<style is:inline define:vars={{color:'green'}}>h1{color:var(--color)}</style>",
want: want{
code: `<style>h1{color:var(--color)}</style>`,
},
},
{
name: "define:vars on script with StaticExpression turned on",
// 1. An inline script with is:inline - right
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/withastro/compiler.git"
},
"scripts": {
"build": "make wasm",
"build": "CGO_ENABLED=0 GOOS=js GOARCH=wasm go build \"-ldflags=-s -w\" -trimpath -o ./packages/compiler/wasm/astro.wasm ./cmd/astro-wasm/astro-wasm.go",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that it isn't necessary to install make to contribute to the project, just pnpm and go.

"build:compiler": "pnpm --filter @astrojs/compiler run build",
"build:all": "pnpm run build && pnpm run build:compiler",
"lint": "eslint \"packages/**/src/**/*.{cjs,js,jsx,mjs,ts,tsx}\"",
Expand Down