summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/compiler/codegen/index.ts8
-rw-r--r--packages/astro/src/compiler/codegen/utils.ts2
2 files changed, 6 insertions, 4 deletions
diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts
index 96c4f5a74..09bd95b46 100644
--- a/packages/astro/src/compiler/codegen/index.ts
+++ b/packages/astro/src/compiler/codegen/index.ts
@@ -22,7 +22,7 @@ import { transform } from '../transform/index.js';
import { PRISM_IMPORT } from '../transform/prism.js';
import { nodeBuiltinsSet } from '../../node_builtins.js';
import { readFileSync } from 'fs';
-import { pathToFileURL } from 'url';
+import { fileURLToPath, pathToFileURL } from 'url';
const { parse, FEATURE_CUSTOM_ELEMENT } = astroParser;
const traverse: typeof babelTraverse.default = (babelTraverse.default as any).default;
@@ -61,6 +61,7 @@ function findHydrationAttributes(attrs: Record<string, string>): HydrationAttrib
/** Retrieve attributes from TemplateNode */
async function getAttributes(nodeName: string, attrs: Attribute[], state: CodegenState, compileOptions: CompileOptions): Promise<Record<string, string>> {
+ const isPage = state.filename.startsWith(fileURLToPath(compileOptions.astroConfig.pages));
let result: Record<string, string> = {};
for (const attr of attrs) {
if (attr.type === 'Spread') {
@@ -112,8 +113,9 @@ async function getAttributes(nodeName: string, attrs: Attribute[], state: Codege
}
case 'Text': {
let text = getTextFromAttribute(val);
-
- warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
+ if (!isPage) {
+ warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
+ }
result[attr.name] = JSON.stringify(text);
continue;
}
diff --git a/packages/astro/src/compiler/codegen/utils.ts b/packages/astro/src/compiler/codegen/utils.ts
index 9f7c8672e..d32ec9aa2 100644
--- a/packages/astro/src/compiler/codegen/utils.ts
+++ b/packages/astro/src/compiler/codegen/utils.ts
@@ -24,7 +24,7 @@ export function isImportMetaDeclaration(declaration: VariableDeclarator, metaNam
const warnableRelativeValues = new Set(['img+src', 'a+href', 'script+src', 'link+href', 'source+srcset']);
-const matchesRelative = /^(?![A-Za-z][+-.0-9A-Za-z]*:|\/)/;
+const matchesRelative = /^(?![A-Za-z][+-.0-9A-Za-z]*:|\/|#)/;
export function warnIfRelativeStringLiteral(logging: LogOptions, nodeName: string, attr: Attribute, value: string) {
let key = nodeName + '+' + attr.name;