GithubHelp home page GithubHelp logo

Comments (16)

egoist avatar egoist commented on May 23, 2024

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

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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' );

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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 ...

from konan.

egoist avatar egoist commented on May 23, 2024

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

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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 ... !?

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

It's VERY confusing!

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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!

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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.

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

'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 ... ?

from konan.

egoist avatar egoist commented on May 23, 2024

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?

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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);

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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 ...

from konan.

egoist avatar egoist commented on May 23, 2024

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

from konan.

sabsaxo avatar sabsaxo commented on May 23, 2024

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);

from konan.

egoist avatar egoist commented on May 23, 2024

https://github.com/egoist/konan/blob/master/test/index.test.js

it works for me

from konan.

limichange avatar limichange commented on May 23, 2024

@sabsaxo I think you should make an example by codesandbox

from konan.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.