Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please, provide a more descriptive example in the Usage section. #5

Open
sabsaxo opened this issue Mar 5, 2018 · 16 comments
Open

Please, provide a more descriptive example in the Usage section. #5

sabsaxo opened this issue Mar 5, 2018 · 16 comments

Comments

@sabsaxo
Copy link

sabsaxo commented Mar 5, 2018

It's not clear how to actually use this. The example strings are out of context, so it's hard to 'guess' what to actually pass to the module.

Can it be used like this?:

let result = konan( 'path/to/script_to_traverse.js' );
@egoist
Copy link
Owner

egoist commented Mar 5, 2018

hmm see https://github.com/egoist/konan#api

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

Not sure I get this. You pass a file entry point ('path_to_file.js') to 'detective' ... I can't seem to understand this sentense:

Source content as string or AST tree.

What is 'Source content'? And I thought that an AST would be what I would get back from konan, not pass into it ... !?

So I ask again:

Can it be used like this?:

let result = konan( 'path/to/script_to_traverse.js' );

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

I can only generate this error: Error: You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a undefined node without passing scope and parentPath. Which does not help me in 'guessing' what to pass to the module. Maybe the 'Like detective but also supports ES6 import and more.' statement is not the right thing to state in the beginning of the readme. As it seem to give the wrong impression ...

@egoist
Copy link
Owner

egoist commented Mar 5, 2018

Source content means the JS code/AST you want to traverse.

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

But then I need ANOTHER module to get the AST from the code!? I would expect konan to return THAT based upon a file path I pass to it ... !?

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

It's VERY confusing!

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

Could you please provide an example where you simply pass in a file path as a string ... IF that's how I can use it!

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

This code:

konan(`
	import React, {Component} from 'react'

	const vue = require('vue/dist/vue')

	import('./my-async-module').then()
	
	require(path.resolve('./'))
`)

simply doesn't make any sense.

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

'detective' works like this:

var detective = require('detective');
var fs = require('fs');

var src = fs.readFileSync(__dirname + '/strings_src.js');
var requires = detective(src);
console.dir(requires);

And I can't see how that matches how 'konan' works ... ?

@egoist
Copy link
Owner

egoist commented Mar 5, 2018

like I said, code or AST:

const code = `
console.log('js code')
`

konan(code)

//-------------- or hmm read the content from a script

const fs = require('fs')
const content = fs.readFileSync('./your/script', 'utf8')
konan(content)

//-------------- or if you already have an AST tree
konan(ast)

Does this make sense to you?

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

Well, it only tell me that the module does NOT work like 'detective`.

And that's why I get errors when trying to do this:

const konan = require('konan');
let src = fs.readFileSync( path + '/index.js' ); // path is the path to the module folder.

let requires = konan( src );

console.log("Requires", requires, src);

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

It keep throwing this at me:

Error: You must pass a scope and parentPath unless traversing a Program/File. Instead of that you tried to traverse a undefined node without passing scope and parentPath.

Please, provide complete example of what scope and parenPath is ...

@egoist
Copy link
Owner

egoist commented Mar 5, 2018

There're edge cases when it says like but not same

The input must be a utf8 string not the buffer you're currently passing to konan

@sabsaxo
Copy link
Author

sabsaxo commented Mar 5, 2018

I've done this as well, but still the same:

const detective = require('detective');
const konan = require('konan');
let src = fs.readFileSync( path + '/index.js', 'utf8');

let requires = konan( src );

console.log("Requires", requires, src);

@egoist
Copy link
Owner

egoist commented Mar 5, 2018

@limichange
Copy link

@sabsaxo I think you should make an example by codesandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants