@babel/types#ImportDefaultSpecifier TypeScript Examples
The following examples show how to use
@babel/types#ImportDefaultSpecifier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: babel-polyfill.ts From nota with MIT License | 6 votes |
importDeclaration = (
specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>,
source: StringLiteral
): ImportDeclaration => ({
type: "ImportDeclaration",
specifiers,
source,
...baseNode,
})
Example #2
Source File: get-sorted-nodes-modules-names.ts From prettier-plugin-sort-imports with Apache License 2.0 | 6 votes |
getSortedNodesModulesNames = (
modules: (
| ImportSpecifier
| ImportDefaultSpecifier
| ImportNamespaceSpecifier
)[],
) =>
modules
.filter((m) =>
[
'ImportSpecifier',
'ImportDefaultSpecifier',
'ImportNamespaceSpecifier',
].includes(m.type),
)
.map((m) => m.local.name)
Example #3
Source File: resolveJsxComponent.ts From react-optimized-image with MIT License | 5 votes |
resolveImport = (binding: Binding | undefined): { exportName?: string; moduleName?: string } | undefined => {
// handle import statements
if (
binding &&
binding.kind === 'module' &&
isImport(binding.path) &&
binding.path.parent.type === 'ImportDeclaration'
) {
return {
moduleName: binding.path.parent.source.value,
exportName: getExportName(binding.path.node as ImportSpecifier | ImportDefaultSpecifier),
};
}
// handle require statements and other libraries like styled-components
if (binding && binding.kind !== 'module' && binding.path.node.type === 'VariableDeclarator') {
const { node } = binding.path;
// check for require('react-optimized-image').default calls
if (node.init && node.init.type === 'MemberExpression' && node.init.object.type === 'CallExpression') {
return {
moduleName: resolveRequireModule(node.init.object),
exportName: resolveRequireExportName(node, binding),
};
}
// check for `const { Svg } = require('react-optimized-image')` or `styled(Img)({}) calls
if (node.init && node.init.type === 'CallExpression') {
// handle styled-components
if (node.init.callee.type === 'CallExpression' && node.init.callee.callee.type === 'Identifier') {
return resolveStyledComponentsImport(node.init.callee, binding);
}
// handle transpiled styled-components
if (
node.init.callee.type === 'CallExpression' &&
node.init.callee.callee.type === 'MemberExpression' &&
node.init.callee.callee.object.type === 'CallExpression'
) {
return resolveStyledComponentsImport(node.init.callee.callee.object, binding);
}
return {
moduleName: resolveRequireModule(node.init),
exportName: resolveRequireExportName(node, binding),
};
}
// handle styled-components (styled(Img)`...`)
if (
node.init &&
node.init.type === 'TaggedTemplateExpression' &&
node.init.tag.type === 'CallExpression' &&
node.init.tag.callee.type === 'Identifier'
) {
return resolveStyledComponentsImport(node.init.tag, binding);
}
// handle recursiveness
if (node.init && node.init.type === 'Identifier') {
return resolveImport(binding.scope.getBinding(node.init.name));
}
}
return undefined;
}
Example #4
Source File: traverse.ts From react-optimized-image with MIT License | 5 votes |
getExportName = (node: ImportSpecifier | ImportDefaultSpecifier): string => {
if (node.type === 'ImportDefaultSpecifier') {
return 'default';
}
return node.imported.name;
}
Example #5
Source File: babel-polyfill.ts From nota with MIT License | 5 votes |
importDefaultSpecifier = (local: Identifier): ImportDefaultSpecifier => ({
type: "ImportDefaultSpecifier",
local,
...baseNode,
})