Comments (3)
Happy to see others benefitting from this project! Is there anything specific you wanted to merge into the main project?
from import-js.
nah .. i tried to fix import paths of fiduswriter
fiduswriter is organized in modules, which are overlaid/merged in the build step
i ended up simply using the original build process (merge the module folders)
why not importjs?
importjs made some errors, probably some exports were ambiguous
and:
importjs can only parse dynamic imports like
var someModule = await import("./some/file.js");
but importjs fails to parse dynamic imports a la
import("./some/file.js").then(({ someProp }) => { someProp(); });
i started writing a parser for that ...
// lib/findCurrentImports.js
// function convertToImportStatement
// import("../../exporter/docx").then(({ DocxExporter }) => { DocxExporter.foo(); });
if (node.type === 'CallExpression') {
if (node.callee.type !== 'MemberExpression') return undefined;
if (node.callee.object.type !== 'CallExpression') return undefined;
if (node.callee.object.callee.type !== 'Import') return undefined;
console.log(`found CallExpression + Import`)
if (node.callee.object.arguments.length !== 1) return undefined;
if (node.callee.object.arguments[0].type !== 'StringLiteral') return undefined;
const path = node.callee.object.arguments[0].value;
// must be relative path
if (!path.startsWith('./') && !path.startsWith('../')) return undefined;
console.log(`found relative path:`)
console.dir(path);
if (node.callee.property.type !== 'Identifier') return undefined;
if (node.callee.property.name !== 'then') return undefined;
console.log(`found CallExpression + Import + then`)
if (node.callee.arguments.length !== 1) return undefined;
if (node.callee.arguments[0].type !== 'ArrowFunctionExpression') return undefined;
console.log(`found CallExpression + Import + then + ArrowFunctionExpression`)
if (node.callee.arguments[0].params.length !== 1) return undefined;
// TODO params[0].type can also be Identifier to import the default export
// TODO support prop renaming: import("./x").then( ({ foo: bar }) => { bar(); } );
if (node.callee.arguments[0].params[0].type !== 'ObjectPattern') return undefined;
console.log(`found CallExpression + Import + then + ArrowFunctionExpression + ObjectPattern`)
if (node.callee.arguments[0].params[0].properties.length > 0) return undefined;
const namedImports = node.callee.arguments[0].params[0].properties.map((p: Object): Object => ({
//localName: p.key.name, // prop renaming: key != value
localName: p.value.name,
}));
console.log(`found namedImports:`)
console.dir(namedImports);
//const defaultImport = declaration.id.type === 'Identifier'
// ? declaration.id.name
// : undefined;
//const namedImports = declaration.id.type === 'ObjectPattern'
// ? declaration.id.properties.map((p: Object): Object => ({
// localName: p.value.name,
// }))
// : undefined;
return new ImportStatement({
declarationKeyword: node.kind,
defaultImport: undefined, // TODO
hasSideEffects: false,
importFunction: undefined, // node.callee.object.callee.name, // always undefined
namedImports,
path,
danglingCommas: false,
});
}
from import-js.
Hey all,
I'm closing this due to inactivity, but if you feel there's still something here we ought to have a look on then please reopen it. Thanks.
from import-js.
Related Issues (20)
- Support for jsconfig.json HOT 7
- Option to import with double quotes instead of single quotes HOT 2
- Lodash alias doesn't work HOT 3
- groupImports ends up grouping namedExports separately. HOT 1
- Import maps HOT 2
- Unable to import files when using smart pipeline operator HOT 5
- Fails to install: node-pre-gyp? HOT 4
- when i move a personal module file to an other folder, the import suggestion of the personal module propose the old folder and the new folder HOT 2
- Config file can't be loaded inside an ES Module project HOT 1
- Move away from Flow? HOT 14
- Move to Prettier, abandon ESlint HOT 4
- Cleaning up stale issues & PRs HOT 2
- Abandon old node versions, update test matrix HOT 2
- React Imports on JSX HOT 1
- Reintroduce some ESlint rules
- Better schema validation errors
- Auto-generate configuration documentation
- Add plugin support HOT 2
- Missing CODECLIMATE_REPO_TOKEN for Github Actions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from import-js.