Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (hasDefaultProps) {
const defaultPropsAst = buildDefaultPropsAst(componentClassName, uidl.propDefinitions)
chunks.push({
type: ChunkType.AST,
fileType: FileType.JS,
name: defaultPropsChunkName,
linkAfter: [componentChunkName],
content: defaultPropsAst,
})
exportChunk.linkAfter.push(defaultPropsChunkName)
}
chunks.push({
type: ChunkType.AST,
fileType: FileType.JS,
name: typesOfPropsChunkName,
linkAfter: [componentChunkName],
content: typesOfPropsAst,
})
// push export of component after declarations of types
exportChunk.linkAfter.push(typesOfPropsChunkName)
return structure
}
},
group: {
openingElement: {
name: {
name: 'Fragment',
},
attributes: [],
},
children: [],
},
},
dynamicRefPrefix: {
prop: 'props.',
},
},
type: ChunkType.AST,
fileType: FileType.JS,
linkAfter: ['import-local'],
content: {},
}
it('adds nothing on the AST if not styles are defined', async () => {
const uidlSample = component('StyledJSX', elementNode('container'))
const structure: ComponentStructure = {
uidl: uidlSample,
options: {},
chunks: [componentChunk],
dependencies: {},
}
const oldStructure = JSON.stringify(structure)
await plugin(structure)
name: 'jsx-component',
meta: {
nodesLookup: {
container: {
openingElement: {
name: {
name: '',
},
},
},
},
dynamicRefPrefix: {
prop: 'props.',
},
},
type: ChunkType.AST,
fileType: FileType.JS,
linkAfter: ['import-local'],
content: {},
}
it('Should not add styled as dependency', async () => {
const uidlSample = component('StyledComponents', elementNode('container'))
const structure: ComponentStructure = {
uidl: uidlSample,
options: {},
chunks: [componentChunk],
dependencies: {},
}
const { dependencies } = await plugin(structure)
const uidlSample = component('SimpleComponent', elementNode('container'))
uidlSample.node.content.key = 'container'
uidlSample.seo = {
metaTags: [
{
name: 'description',
value: 'test',
},
{
randomKey: 'randomValue',
},
],
}
const jsChunk: ChunkDefinition = {
type: ChunkType.AST,
fileType: FileType.JS,
name: 'vue-js-chunk',
content: {
declaration: {
properties: [],
},
},
linkAfter: [],
}
const structure: ComponentStructure = {
uidl: uidlSample,
options: {},
chunks: [jsChunk],
dependencies: {},
}
options: {},
chunks: [],
dependencies: {},
}
const { dependencies, chunks } = await stencilAppRouting(structure)
expect(chunks.length).toBe(2)
expect(Object.keys(dependencies).length).toBe(2)
expect(chunks[0].name).toBe('component-decorator')
expect(chunks[0].fileType).toBe(FileType.TSX)
expect(chunks[0].type).toBe(ChunkType.AST)
expect(chunks[0].content).toBeDefined()
expect(chunks[1].name).toBe('jsx-component')
expect(chunks[1].fileType).toBe(FileType.TSX)
expect(chunks[1].type).toBe(ChunkType.AST)
expect(chunks[1].content).toBeDefined()
})
})
const uidlSample = component('SimpleComponent', elementNode('container'), props)
const structure: ComponentStructure = {
uidl: uidlSample,
options: {},
chunks: [reactChunk, exportChunk],
dependencies: {},
}
const result = await plugin(structure)
const defaultProps = result.chunks.filter((chunk) => chunk.name === 'component-default-props')
const propTypes = result.chunks.filter((chunk) => chunk.name === 'component-types-of-props')
expect(defaultProps.length).toEqual(0)
expect(propTypes.length).toEqual(1)
expect(propTypes[0].type).toBe(ChunkType.AST)
})
linkAfter: [],
})
const stateObject = uidl.stateDefinitions ? extractStateObject(uidl.stateDefinitions) : {}
const jsContent = generateVueComponentJS(
uidl,
Object.keys(dependencies),
{
...stateObject,
...dataObject,
},
methodsObject
)
chunks.push({
type: ChunkType.AST,
name: vueJSChunkName,
fileType: FileType.JS,
linkAfter: jsChunkAfter,
content: jsContent,
})
return structure
}
t.stringLiteral(`./${StringUtils.camelCaseToDashCase(component)}`)
)
})
let exportSpecifiers = []
exportSpecifiers = Object.keys(components).map((component) =>
t.exportSpecifier(
t.identifier(StringUtils.capitalize(component)),
t.identifier(StringUtils.capitalize(component))
)
)
const exportAST = t.exportNamedDeclaration(null, exportSpecifiers)
chunks.push({
name: importChunkName,
type: ChunkType.AST,
fileType: FileType.JS,
content: importsAST,
linkAfter: [],
})
chunks.push({
name: exportChunkName,
type: ChunkType.AST,
fileType: FileType.JS,
content: exportAST,
linkAfter: [importChunkName],
})
return structure
}
})
const exportChunk = chunks.find((chunk) => chunk.name === exportChunkName)
const componentName = UIDLUtils.getComponentClassName(uidl)
const exportStatement = ASTBuilders.createReactJSSDefaultExport(
componentName,
jssDeclarationName
)
if (exportChunk) {
exportChunk.content = exportStatement
exportChunk.linkAfter = [importChunkName, styleChunkName]
} else {
chunks.push({
type: ChunkType.AST,
fileType: FileType.JS,
name: exportChunkName,
content: exportStatement,
linkAfter: [importChunkName, styleChunkName],
})
}
return structure
}
slotHandling: 'props',
}
const jsxTagStructure = createJSXSyntax(uidl.node, jsxParams, jsxOptions)
if (!usePureComponent) {
dependencies.Component = PREACT_COMPONENT_DEPENDENCY
}
const componentName = UIDLUtils.getComponentClassName(uidl)
const preactComponent = usePureComponent
? createPureComponent(componentName, propDefinitions, jsxTagStructure)
: createClassComponent(componentName, propDefinitions, stateDefinitions, jsxTagStructure)
structure.chunks.push({
type: ChunkType.AST,
fileType: FileType.JS,
name: componentChunkName,
meta: {
nodesLookup,
dynamicRefPrefix: jsxOptions.dynamicReferencePrefixMap,
},
content: preactComponent,
linkAfter: [importChunkName],
})
structure.chunks.push({
type: ChunkType.AST,
fileType: FileType.JS,
name: exportChunkName,
content: ASTBuilders.createDefaultExport(componentName),
linkAfter: [componentChunkName],