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

Astro.resolve #1085

Merged
merged 9 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use the astro logger to log the warning
  • Loading branch information
matthewp committed Aug 16, 2021
commit 331dfaf1cbfcf0bcc29230ebe62f348437b7f28b
3 changes: 2 additions & 1 deletion packages/astro/src/compiler/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ async function getAttributes(nodeName: string, attrs: Attribute[], state: Codege
}
case 'Text': {
let text = getTextFromAttribute(val);
warnIfRelativeStringLiteral(nodeName, attr, text);

warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
result[attr.name] = JSON.stringify(text);
continue;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/astro/src/compiler/codegen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import type { VariableDeclarator, CallExpression } from '@babel/types';
import type { Attribute } from './interfaces';
import type { LogOptions } from '../../logger';
import { warn } from '../../logger';

/** Is this an import.meta.* built-in? You can pass an optional 2nd param to see if the name matches as well. */
export function isImportMetaDeclaration(declaration: VariableDeclarator, metaName?: string): boolean {
Expand All @@ -30,9 +32,10 @@ const warnableRelativeValues = new Set([

const nonRelative = /^(?!(https?|\/))/;
matthewp marked this conversation as resolved.
Show resolved Hide resolved
matthewp marked this conversation as resolved.
Show resolved Hide resolved

export function warnIfRelativeStringLiteral(nodeName: string, attr: Attribute, value: string) {
export function warnIfRelativeStringLiteral(logging: LogOptions, nodeName: string, attr: Attribute, value: string) {
let key = nodeName + '+' + attr.name;
if(warnableRelativeValues.has(key) && nonRelative.test(value)) {
console.warn(`This value will be resolved relative to the page: <${nodeName} ${attr.name}="${value}">`);
let message = `This value will be resolved relative to the page: <${nodeName} ${attr.name}="${value}">`;
warn(logging, 'relative-link', message);
}
}