Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
insertElementAdjacentToChild(position) {
const { containerPath, currentOperation, onWarning } = this;
const { targetChild, componentPath } = currentOperation;
const targetChildPath = this.findContainerChildByName(targetChild);
if (!targetChildPath) {
onWarning(
`Attempted to inject a PWA Studio extension, but specified targetChild was not found\n` +
`operation: ${currentOperation.operation}\n` +
`targetContainer: ${currentOperation.targetContainer}\n` +
`targetChild: ${currentOperation.targetChild}`
);
return;
}
const componentIdent = addDefault(targetChildPath, componentPath, {
nameHint: 'Extension'
}).name;
// TODO: extensionNode needs to be wrapped in a new ContainerChild,
// and an error boundary
const extensionNode = this.buildCreateElementCall(componentIdent);
this.insertAdjacentArgumentsNode(
position,
containerPath,
targetChildPath.node,
extensionNode
);
}
importMethod(methodName, file, pluginState) {
if (!pluginState.selectedMethods[methodName]) {
const libraryDirectory = this.libraryDirectory;
const style = this.style;
const transformedMethodName = this.camel2UnderlineComponentName // eslint-disable-line
? transCamel(methodName, '_')
: this.camel2DashComponentName
? transCamel(methodName, '-')
: methodName;
const path = winPath(
this.customName ? this.customName(transformedMethodName) : join(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) // eslint-disable-line
);
pluginState.selectedMethods[methodName] = this.transformToDefaultImport // eslint-disable-line
? addDefault(file.path, path, { nameHint: methodName })
: addNamed(file.path, methodName, path);
if (this.customStyleName) {
const stylePath = winPath(this.customStyleName(transformedMethodName));
addSideEffect(file.path, `${stylePath}`);
} else if (this.styleLibraryDirectory) {
const stylePath = winPath(
join(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName)
);
addSideEffect(file.path, `${stylePath}`);
} else if (style === true) {
addSideEffect(file.path, `${path}/style`);
} else if (style === 'css') {
addSideEffect(file.path, `${path}/style/css`);
} else if (typeof style === 'function') {
const stylePath = style(path, file);
if (stylePath) {
});
}
replacement = buildFuncMock({
FUNC: builderFuncId,
ENDPOINT: t.stringLiteral(endpoint),
});
} else {
const data = config.urlMap[endpoint];
if (!data) {
throw new MacroError('flask-url.macro must reference a valid flask endpoint');
}
// generate import
if (!builderFuncId) {
builderFuncId = addDefaultImport(state.file.path, config.builder, {
nameHint: 'buildFlaskURL',
});
}
replacement = buildFunc({
FUNC: builderFuncId,
RULE: t.valueToNode(data),
BASE: t.stringLiteral(config.basePath),
});
}
// replace the tagged template expression with the builder function
parentPath.replaceWith(replacement);
});
};
let getOriginalImportPathStyledIdentifier = () => {
if (originalImportPathStyledIdentifier === undefined) {
originalImportPathStyledIdentifier = addDefault(
state.file.path,
originalImportPath,
{
nameHint: 'styled'
}
)
}
return t.cloneDeep(originalImportPathStyledIdentifier)
}
if (importPath === originalImportPath) {
function importDefaultTemplate(path, state) {
const componentName = getBaseName(state);
return moduleImports.addDefault(path, `./${componentName}.html`, {
nameHint: 'tmpl',
});
}
function getAssignIdentifier(path, file, state) {
if (state.id) {
return state.id;
}
state.id = addDefault(path, 'object-assign', { nameHint: 'assign' })
return state.id;
}
let getStyledIdentifier = () => {
if (_styledIdentifier === undefined) {
_styledIdentifier = addDefault(state.file.path, importPath, {
nameHint: 'styled'
})
}
return t.cloneDeep(_styledIdentifier)
}
let originalImportPathStyledIdentifier
function getImport(p, { source, nameHint }) {
return addDefault(p, source, { nameHint })
}
const transformImports = transform.imports.map(importName => {
return addDefault(path, importName, {hint: importName});
});