fix too strict "relative link" errors in docs website (#1149)

This commit is contained in:
Fred K. Schott 2021-08-18 09:05:50 -07:00 committed by GitHub
parent d18402de3a
commit c4e9ce3b14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -22,7 +22,7 @@ import { transform } from '../transform/index.js';
import { PRISM_IMPORT } from '../transform/prism.js'; import { PRISM_IMPORT } from '../transform/prism.js';
import { nodeBuiltinsSet } from '../../node_builtins.js'; import { nodeBuiltinsSet } from '../../node_builtins.js';
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { pathToFileURL } from 'url'; import { fileURLToPath, pathToFileURL } from 'url';
const { parse, FEATURE_CUSTOM_ELEMENT } = astroParser; const { parse, FEATURE_CUSTOM_ELEMENT } = astroParser;
const traverse: typeof babelTraverse.default = (babelTraverse.default as any).default; 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 */ /** Retrieve attributes from TemplateNode */
async function getAttributes(nodeName: string, attrs: Attribute[], state: CodegenState, compileOptions: CompileOptions): Promise<Record<string, string>> { 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> = {}; let result: Record<string, string> = {};
for (const attr of attrs) { for (const attr of attrs) {
if (attr.type === 'Spread') { if (attr.type === 'Spread') {
@ -112,8 +113,9 @@ async function getAttributes(nodeName: string, attrs: Attribute[], state: Codege
} }
case 'Text': { case 'Text': {
let text = getTextFromAttribute(val); let text = getTextFromAttribute(val);
if (!isPage) {
warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text); warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
}
result[attr.name] = JSON.stringify(text); result[attr.name] = JSON.stringify(text);
continue; continue;
} }

View file

@ -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 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) { export function warnIfRelativeStringLiteral(logging: LogOptions, nodeName: string, attr: Attribute, value: string) {
let key = nodeName + '+' + attr.name; let key = nodeName + '+' + attr.name;