Skip to content

Commit

Permalink
Fix for fallback for component name (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaKrishnaNamburu authored Oct 7, 2021
1 parent 3a7c2ba commit 914a4c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/teleport-component-generator-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const createHTMLComponentGenerator: HTMLComponentGeneratorInstance = ({
}: GeneratorFactoryParams = {}): HTMLComponentGenerator => {
const generator = createComponentGenerator()
const { htmlComponentPlugin, addExternals } = createHTMLBasePlugin()
const resolver = new Resolver(PlainHTMLMapping)
const resolver = new Resolver()
resolver.addMapping(PlainHTMLMapping)

Object.defineProperty(generator, 'addExternalComponents', {
value: (params: { externals: Record<string, ComponentUIDL>; skipValidation?: boolean }) => {
Expand All @@ -48,8 +49,9 @@ const createHTMLComponentGenerator: HTMLComponentGeneratorInstance = ({
})
)

generator.addMapping(PlainHTMLMapping)
mappings.forEach((mapping) => generator.addMapping(mapping))
generator.addMapping(PlainHTMLMapping)

plugins.forEach((plugin) => generator.addPlugin(plugin))
generator.addPlugin(importStatementsPlugin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const PlainHTMLMapping: Mapping = {
},
},
},
illegalClassNames: [],
}
19 changes: 10 additions & 9 deletions packages/teleport-plugin-html-base-component/src/node-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
style = {},
referencedStyles = {},
dependency,
semanticType,
} = node.content
const { dependencies, chunks, options } = structure

Expand All @@ -106,17 +107,17 @@ const generatElementNode: NodeToHTML<UIDLElementNode, Promise<HastNode | HastTex
}

if (dependency && dependency?.type === 'local') {
const comp = externals[elementType]
let compName = elementType
let comp = externals[compName]

if (!comp) {
throw new HTMLComponentGeneratorError(
`External component that is referred is missing. Received ${JSON.stringify(
dependency,
null,
2
)} with ${elementType} \n
But received externals ${Object.keys(externals)}`
)
compName = semanticType === 'AppComponent' ? 'Component' : elementType
comp = externals[compName]
if (!comp) {
throw new HTMLComponentGeneratorError(
`${compName} is missing from externals - ${Object.keys(externals)}`
)
}
}

const combinedProps = { ...propDefinitions, ...(comp?.propDefinitions || {}) }
Expand Down
4 changes: 2 additions & 2 deletions packages/teleport-types/src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export enum ProjectType {
GATSBY = 'Gatsby',
GRIDSOME = 'Gridsome',
REACTNATIVE = 'React-Native',
HTML = 'Html',
HTML = 'HTML',
}

export enum ComponentType {
Expand All @@ -498,7 +498,7 @@ export enum ComponentType {
STENCIL = 'Stencil',
ANGULAR = 'Angular',
REACTNATIVE = 'React-Native',
HTML = 'Html',
HTML = 'HTML',
}

export const DefaultStyleVariation: Record<ComponentType, StyleVariation | null> = {
Expand Down

0 comments on commit 914a4c5

Please sign in to comment.