Skip to content

Commit

Permalink
Merge branch 'main' into fix/missing-scope-id-for-user-provided-children
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored May 11, 2024
2 parents 8777dc8 + d345412 commit 833c4c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/compiler/transformers/static-to-meta/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const convertStaticToMeta = (
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
typeChecker: ts.TypeChecker,
collection: d.CollectionCompilerMeta,
collection: d.CollectionCompilerMeta | null,
transformOpts: d.TransformOptions,
): ts.TransformerFactory<ts.SourceFile> => {
return (transformCtx) => {
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/transpile/transpile-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ export const transpileModule = (
const program = ts.createProgram([sourceFilePath], tsCompilerOptions, compilerHost);
const typeChecker = program.getTypeChecker();

const transformers: ts.CustomTransformers = {
const transformers = {
before: [
convertDecoratorsToStatic(config, buildCtx.diagnostics, typeChecker, program),
performAutomaticKeyInsertion,
updateStencilCoreImports(transformOpts.coreImportPath),
],
after: [convertStaticToMeta(config, compilerCtx, buildCtx, typeChecker, null, transformOpts)],
afterDeclarations: [],
};
afterDeclarations: [] as (ts.CustomTransformerFactory | ts.TransformerFactory<ts.SourceFile | ts.Bundle>)[],
} satisfies ts.CustomTransformers;

if (config.transformAliasedImportPaths) {
transformers.before.push(rewriteAliasedSourceFileImportPaths);
Expand All @@ -146,7 +146,7 @@ export const transpileModule = (

program.emit(undefined, undefined, undefined, false, transformers);

const tsDiagnostics = [...program.getSyntacticDiagnostics()];
const tsDiagnostics = [...program.getSyntacticDiagnostics()] as ts.Diagnostic[];

if (config.validateTypes) {
tsDiagnostics.push(...program.getOptionsDiagnostics());
Expand All @@ -156,15 +156,15 @@ export const transpileModule = (

results.diagnostics.push(...buildCtx.diagnostics);

results.moduleFile = compilerCtx.moduleMap.get(results.sourceFilePath);
results.moduleFile = compilerCtx.moduleMap.get(results.sourceFilePath)!;

return results;
};

const getScriptTargetKind = (transformOpts: d.TransformOptions) => {
const target = transformOpts.target && transformOpts.target.toUpperCase();
if (isNumber((ts.ScriptTarget as any)[target])) {
return (ts.ScriptTarget as any)[target];
if (isNumber((ts.ScriptTarget as any)[target as string])) {
return (ts.ScriptTarget as any)[target as string];
}
// ESNext and Latest are the same
return ts.ScriptTarget.Latest;
Expand Down
1 change: 1 addition & 0 deletions src/declarations/stencil-public-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ export namespace JSXBase {
hrefLang?: string;
hreflang?: string;
media?: string;
ping?: string;
rel?: string;
target?: string;
referrerPolicy?: ReferrerPolicy;
Expand Down
20 changes: 12 additions & 8 deletions src/mock-doc/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
}

insertAdjacentElement(position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend', elm: MockHTMLElement) {
if (position === 'beforebegin') {
if (position === 'beforebegin' && this.parentNode) {
insertBefore(this.parentNode, elm, this);
} else if (position === 'afterbegin') {
this.prepend(elm);
} else if (position === 'beforeend') {
this.appendChild(elm);
} else if (position === 'afterend') {
} else if (position === 'afterend' && this.parentNode) {
insertBefore(this.parentNode, elm, this.nextSibling);
}
return elm;
Expand All @@ -497,7 +497,9 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
const frag = parseFragmentUtil(this.ownerDocument, html);
if (position === 'beforebegin') {
while (frag.childNodes.length > 0) {
insertBefore(this.parentNode, frag.childNodes[0], this);
if (this.parentNode) {
insertBefore(this.parentNode, frag.childNodes[0], this);
}
}
} else if (position === 'afterbegin') {
while (frag.childNodes.length > 0) {
Expand All @@ -509,20 +511,22 @@ Testing components with ElementInternals is fully supported in e2e tests.`,
}
} else if (position === 'afterend') {
while (frag.childNodes.length > 0) {
insertBefore(this.parentNode, frag.childNodes[frag.childNodes.length - 1], this.nextSibling);
if (this.parentNode) {
insertBefore(this.parentNode, frag.childNodes[frag.childNodes.length - 1], this.nextSibling);
}
}
}
}

insertAdjacentText(position: 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend', text: string) {
const elm = this.ownerDocument.createTextNode(text);
if (position === 'beforebegin') {
if (position === 'beforebegin' && this.parentNode) {
insertBefore(this.parentNode, elm, this);
} else if (position === 'afterbegin') {
this.prepend(elm);
} else if (position === 'beforeend') {
this.appendChild(elm);
} else if (position === 'afterend') {
} else if (position === 'afterend' && this.parentNode) {
insertBefore(this.parentNode, elm, this.nextSibling);
}
}
Expand Down Expand Up @@ -1077,7 +1081,7 @@ export function resetElement(elm: MockElement) {
delete elm.__style;
}

function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: MockNode) {
function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: MockNode | null) {
if (newNode !== referenceNode) {
newNode.remove();
newNode.parentNode = parentNode;
Expand All @@ -1103,7 +1107,7 @@ function insertBefore(parentNode: MockNode, newNode: MockNode, referenceNode: Mo
export class MockHTMLElement extends MockElement {
override __namespaceURI = 'http://www.w3.org/1999/xhtml';

constructor(ownerDocument: any, nodeName: string) {
constructor(ownerDocument: any, nodeName: string | null) {
super(ownerDocument, typeof nodeName === 'string' ? nodeName.toUpperCase() : null);
}

Expand Down

0 comments on commit 833c4c2

Please sign in to comment.