@gluonjs/compiler / packages/compiler/src / GluonTransformResult
Interface: GluonTransformResult
Properties
code
readonlycode:string
decorators
readonlydecorators:boolean
diagnostics
readonlydiagnostics: readonlyGluonCompilerDiagnostic[]
hmr
readonlyhmr:boolean
map
readonlymap:GluonSourceMap
templates
readonlytemplates: readonlyGluonTemplateLocation[]
Example
Consume transformed code, source map, diagnostics, template locations, and the fact that HMR instrumentation changed the module:
import {
transformGluonModule,
transpileGluonDecorators,
type GluonCompilerDiagnostic,
type GluonDecoratorMode,
type GluonSourceMap,
type GluonTemplateLocation,
type GluonTemplatePart,
type GluonTemplateTag,
type GluonTransformOptions,
type GluonTransformResult,
type GluonTranspileResult,
type SourceLocation,
} from '@gluonjs/compiler';
const source = `
import { html } from '@gluonjs/core';
export const Product = (name: string) => html\`<h1>\${name}</h1>\`;
`;
const options = { development: true } satisfies GluonTransformOptions;
const result: GluonTransformResult = transformGluonModule(source, '/src/product.ts', options);
const map: GluonSourceMap = result.map;
const template: GluonTemplateLocation | undefined = result.templates[0];
const tag: GluonTemplateTag | undefined = template?.tag;
const part: GluonTemplatePart | undefined = template?.parts[0];
const start: SourceLocation | undefined = part?.start;
const diagnostic: GluonCompilerDiagnostic | undefined = result.diagnostics[0];
const mode: GluonDecoratorMode = 'standard';
const transpiled: GluonTranspileResult = transpileGluonDecorators(result.code, '/src/product.ts', mode);
console.log(result.code, transpiled.code, map.sources, tag, start, diagnostic?.message, result.hmr);