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

[WIP] feat: expose AST parser API to Deno namespace. #6893

Closed
wants to merge 25 commits into from

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jul 27, 2020

Closes #3983

Exposes swc's AST parser API to the runtime behind the --unstable flag.

await Deno.ast("file1.ts"); // uses default options

Prior Art:
N/A - this feature is specific to the runtime compiler ops.

Corresponding command:
deno ast file.ts --unstable

Points:

@littledivy littledivy marked this pull request as draft July 27, 2020 12:44
@CLAassistant
Copy link

CLAassistant commented Jul 27, 2020

CLA assistant check
All committers have signed the CLA.

@littledivy littledivy changed the title expose AST parser API to runtime. feat: expose AST parser API to Deno namespace. Jul 28, 2020
cli/ops/runtime_compiler.rs Outdated Show resolved Hide resolved
cli/swc_util.rs Outdated Show resolved Hide resolved
cli/swc_util.rs Outdated Show resolved Hide resolved
cli/swc_util.rs Outdated Show resolved Hide resolved
cli/tsc.rs Outdated Show resolved Hide resolved
@littledivy littledivy changed the title feat: expose AST parser API to Deno namespace. [WIP] feat: expose AST parser API to Deno namespace. Jul 28, 2020
@ry ry added this to the 1.3.0 milestone Aug 3, 2020
@SyrupThinker
Copy link
Contributor

What is the reason for taking a file name and reading the file instead of passing name and source code to Deno.ast?
That'd be more in line with how Deno.{bundle, compile, transpileOnly} work.

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Aug 5, 2020

I think we're supposed to support both:

namespace Deno {
  export type AstOptions = {
    /** Name of the file or URL of the module. Where applicable, it will be
     * downloaded and cached before being parsed. */
    name: string;
    // Other options...
  } | {
    /** Source of the module. It will be parsed without side-effect. */
    source: string;
    // Other options...
  };;

  export function ast(options: AstOptions): Module;
}

Or even simpler if the name should be provided either way.


// --- AST Nodes ---

export interface Span {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these being put into the global scope or something?

Copy link
Member Author

@littledivy littledivy Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, these are the AST return types but I'm unable to refer the Module type in deno.unstable.d.ts

@ry ry removed this from the 1.3.0 milestone Aug 12, 2020
@ry
Copy link
Member

ry commented Aug 12, 2020

We are having an internal debate about whether we actually want this feature - we can't reach consensus. Because of that I don't want to land for 1.3.0. Removing the milestone.

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

Successfully merging this pull request may close these issues.

Use swc to expose an AST to the runtime
6 participants