From 8600406afa290be35ba7bb4ff245cbf18aa0a2e1 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 14:26:11 -0600 Subject: [PATCH 01/12] fix: multibyte characters in sourcemap --- internal/printer/printer_test.go | 15 +++++++++++++++ internal/sourcemap/sourcemap.go | 15 ++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index a4294316e..11dca8dcb 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -2872,6 +2872,21 @@ const items = ["Dog", "Cat", "Platipus"]; code: `${($$render` + BACKTICK + `${$$renderComponent($$result,'Fragment',Fragment,{},{"default": () => $$render` + BACKTICK + `${$$renderComponent($$result,'Fragment',Fragment,{},{"default": () => $$render` + BACKTICK + `${$$unescapeHTML(` + BACKTICK + `<${Node.tag} ${stringifyAttributes(Node.attributes)}>` + BACKTICK + `)}` + BACKTICK + `,})}${Node.children.map((child) => ($$render` + BACKTICK + `${$$renderComponent($$result,'Astro.self',Astro.self,{"node":(child)})}` + BACKTICK + `))}${$$renderComponent($$result,'Fragment',Fragment,{},{"default": () => $$render` + BACKTICK + `${$$unescapeHTML(` + BACKTICK + `` + BACKTICK + `)}` + BACKTICK + `,})}` + BACKTICK + `,})}` + BACKTICK + `)}`, }, }, + { + name: "multibyte character + style", + source: ``, + only: true, + want: want{ + code: `${$$maybeRenderHead($$result)}`, + }, + }, + { + name: "multibyte character + script", + source: ``, + want: want{ + code: `${$$maybeRenderHead($$result)}`, + }, + }, { name: "transition:name with an expression", source: `
`, diff --git a/internal/sourcemap/sourcemap.go b/internal/sourcemap/sourcemap.go index 988201b18..3d2feff58 100644 --- a/internal/sourcemap/sourcemap.go +++ b/internal/sourcemap/sourcemap.go @@ -73,12 +73,11 @@ var base64 = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456 // bit. The continuation bit tells us whether there are more digits in this // value following this digit. // -// Continuation -// | Sign -// | | -// V V -// 101011 -// +// Continuation +// | Sign +// | | +// V V +// 101011 func EncodeVLQ(value int) []byte { var vlq int if value < 0 { @@ -675,7 +674,9 @@ func (b *ChunkBuilder) AddSourceMapping(location loc.Loc, output []byte) { line := &lineOffsetTables[originalLine] originalColumn := int(location.Start - line.byteOffsetToStartOfLine) if line.columnsForNonASCII != nil && originalColumn >= int(line.byteOffsetToFirstNonASCII) { - originalColumn = int(line.columnsForNonASCII[originalColumn-int(line.byteOffsetToFirstNonASCII)]) + if len(line.columnsForNonASCII) > originalColumn-int(line.byteOffsetToFirstNonASCII) { + originalColumn = int(line.columnsForNonASCII[originalColumn-int(line.byteOffsetToFirstNonASCII)]) + } } b.updateGeneratedLineAndColumn(output) From 8511debabfe8409f31f1fe80246a496b33a88b8c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 14:54:15 -0600 Subject: [PATCH 02/12] chore: add test for #9421 --- internal/printer/printer_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 11dca8dcb..68eab698f 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -2875,18 +2875,29 @@ const items = ["Dog", "Cat", "Platipus"]; { name: "multibyte character + style", source: ``, - only: true, want: want{ code: `${$$maybeRenderHead($$result)}`, }, }, + { + name: "multibyte characters", + source: `--- +--- +

こんにちは

`, + want: want{ + code: `${$$maybeRenderHead($$result)}

こんにちは

`, + }, + }, + { name: "multibyte character + script", source: ``, want: want{ - code: `${$$maybeRenderHead($$result)}`, + code: `${$$maybeRenderHead($$result)}`, + metadata: metadata{hoisted: []string{fmt.Sprintf(`{ type: 'inline', value: %sconsole.log('foo')%s }`, BACKTICK, BACKTICK)}}, }, }, + { name: "transition:name with an expression", source: `
`, From 94073ec933f970d76a06b275d20f615d1399864d Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 14:55:10 -0600 Subject: [PATCH 03/12] chore: add changeset --- .changeset/dull-bees-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-bees-grab.md diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md new file mode 100644 index 000000000..bb04f3d27 --- /dev/null +++ b/.changeset/dull-bees-grab.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Fixes a fatal `index out of range` error when multibyte characters were rendered as markup From 43e800d71efe5dce060cf5e3df16a134ac435c39 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 15:26:23 -0600 Subject: [PATCH 04/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index bb04f3d27..be81046d2 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fixes a fatal `index out of range` error when multibyte characters were rendered as markup +Fix an `index out of range` error when multibyte characters were rendered as markup From d766729857f55153614c3e6aa926da9762342c8f Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 16:51:49 -0600 Subject: [PATCH 05/12] chore: force ci From 58f9aa261c176e30f8b2a05aa350758287e879d3 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 16:52:34 -0600 Subject: [PATCH 06/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index be81046d2..fad1ce769 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fix an `index out of range` error when multibyte characters were rendered as markup +Fix a `index out of range` error when multibyte characters were rendered as markup From ea202a577987e567b1eb3070fd755855ce2f4ba9 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 16:55:49 -0600 Subject: [PATCH 07/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index fad1ce769..be81046d2 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fix a `index out of range` error when multibyte characters were rendered as markup +Fix an `index out of range` error when multibyte characters were rendered as markup From 8ff18a8c826adc5b19ab692cb811eb3e1797ee22 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 16:59:46 -0600 Subject: [PATCH 08/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index be81046d2..d35f80931 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fix an `index out of range` error when multibyte characters were rendered as markup +Fixed an `index out of range` error when multibyte characters were rendered as markup From 3ef8cdf8fed911166c267abc44dbd9abf74de4f6 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 17:01:32 -0600 Subject: [PATCH 09/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index d35f80931..e0640a3d2 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Fixed an `index out of range` error when multibyte characters were rendered as markup +Will fix an `index out of range` error when multibyte characters were rendered as markup From d10707245dfb5937934709fe3d4dd6ad21638a35 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Dec 2023 17:04:22 -0600 Subject: [PATCH 10/12] chore: update changeset --- .changeset/dull-bees-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dull-bees-grab.md b/.changeset/dull-bees-grab.md index e0640a3d2..d35f80931 100644 --- a/.changeset/dull-bees-grab.md +++ b/.changeset/dull-bees-grab.md @@ -2,4 +2,4 @@ '@astrojs/compiler': patch --- -Will fix an `index out of range` error when multibyte characters were rendered as markup +Fixed an `index out of range` error when multibyte characters were rendered as markup From 525b6ccfdd8c663773ebbb52900f04547758bcf0 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 14 Dec 2023 14:18:34 -0600 Subject: [PATCH 11/12] test: add sourcemap tests --- .../compiler/test/tsx-sourcemaps/multibyte.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 packages/compiler/test/tsx-sourcemaps/multibyte.ts diff --git a/packages/compiler/test/tsx-sourcemaps/multibyte.ts b/packages/compiler/test/tsx-sourcemaps/multibyte.ts new file mode 100644 index 000000000..b6001d64b --- /dev/null +++ b/packages/compiler/test/tsx-sourcemaps/multibyte.ts @@ -0,0 +1,53 @@ +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import { testTSXSourcemap } from '../utils'; + +test('multibyte content', async () => { + const input = `

`; + + const output = await testTSXSourcemap(input, 'ツ'); + assert.equal(output, { + source: 'index.astro', + line: 1, + column: 4, + name: null, + }); +}); + +test('content after multibyte character', async () => { + const input = `

foobar

`; + + const output = await testTSXSourcemap(input, 'foobar'); + assert.equal(output, { + source: 'index.astro', + line: 1, + column: 13, + name: null, + }); +}); + +test('many characters', async () => { + const input = `

こんにちは

`; + + const output = await testTSXSourcemap(input, 'ん'); + assert.equal(output, { + source: 'index.astro', + line: 1, + column: 5, + name: null, + }); +}); + +test('many characters', async () => { + const input = `

こんにちは

`; + + const output = await testTSXSourcemap(input, 'に'); + assert.equal(output, { + source: 'index.astro', + line: 1, + column: 6, + name: null, + }); +}); + +test.run(); From acf9fe9fc6499b713c03173e4c9c3b634419c8e7 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 14 Dec 2023 14:18:49 -0600 Subject: [PATCH 12/12] chore: disable line terminator warnings --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d9ffe7d80..84d6f0b1d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,6 @@ "go.toolsEnvVars": { "GOOS": "js", "GOARCH": "wasm" - } + }, + "editor.unusualLineTerminators": "off" }