make component_name globally available

pull/16268/head
Rich Harris 3 months ago
parent 13f7fbdb9b
commit be32264673

@ -516,6 +516,7 @@ export function analyze_component(root, source, options) {
}; };
state.reset({ state.reset({
component_name: analysis.name,
dev: options.dev, dev: options.dev,
filename: options.filename, filename: options.filename,
rootDir: options.rootDir, rootDir: options.rootDir,

@ -34,6 +34,7 @@ export interface ReactiveStatement {
*/ */
export interface Analysis { export interface Analysis {
module: Js; module: Js;
/** @deprecated use `component_name` from `state.js` instead */
name: string; // TODO should this be filename? it's used in `compileModule` as well as `compile` name: string; // TODO should this be filename? it's used in `compileModule` as well as `compile`
/** @deprecated use `runes` from `state.js` instead */ /** @deprecated use `runes` from `state.js` instead */
runes: boolean; runes: boolean;
@ -91,6 +92,7 @@ export interface ComponentAnalysis extends Analysis {
keyframes: string[]; keyframes: string[];
has_global: boolean; has_global: boolean;
}; };
/** @deprecated use `source` from `state.js` instead */
source: string; source: string;
undefined_exports: Map<string, Node>; undefined_exports: Map<string, Node>;
/** /**

@ -16,6 +16,8 @@ export let warnings = [];
*/ */
export let filename; export let filename;
export let component_name = '<unknown>';
/** /**
* The original source code * The original source code
* @type {string} * @type {string}
@ -97,6 +99,7 @@ export function is_ignored(node, code) {
* @param {{ * @param {{
* dev: boolean; * dev: boolean;
* filename: string; * filename: string;
* component_name?: string;
* rootDir?: string; * rootDir?: string;
* runes: boolean; * runes: boolean;
* }} state * }} state
@ -105,8 +108,9 @@ export function reset(state) {
const root_dir = state.rootDir?.replace(/\\/g, '/'); const root_dir = state.rootDir?.replace(/\\/g, '/');
filename = state.filename.replace(/\\/g, '/'); filename = state.filename.replace(/\\/g, '/');
dev = !!state.dev; dev = state.dev;
runes = !!state.runes; runes = state.runes;
component_name = state.component_name ?? '(unknown)';
if (typeof root_dir === 'string' && filename.startsWith(root_dir)) { if (typeof root_dir === 'string' && filename.startsWith(root_dir)) {
// make filename relative to rootDir // make filename relative to rootDir

Loading…
Cancel
Save