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

Example does not compile #102

Closed
nevinpuri opened this issue Jun 22, 2022 · 2 comments · Fixed by #103
Closed

Example does not compile #102

nevinpuri opened this issue Jun 22, 2022 · 2 comments · Fixed by #103

Comments

@nevinpuri
Copy link

While trying to run the example:

use deno_ast::parse_module;
use deno_ast::MediaType;
use deno_ast::ParseParams;
use deno_ast::SourceTextInfo;
use std::sync::Arc;

let source_text = Arc::new("class MyClass {}");
let text_info = SourceTextInfo::new(source_text);
let parsed_source = parse_module(ParseParams {
  specifier: "file:///my_file.ts".to_string(),
  media_type: MediaType::TypeScript,
  text_info,
  capture_tokens: true,
  maybe_syntax: None,
  scope_analysis: false,
}).expect("should parse");

// returns the comments
parsed_source.comments();
// returns the tokens if captured
parsed_source.tokens();
// returns the module (AST)
parsed_source.module();
// returns the `SourceTextInfo`
parsed_source.source();

I get an error saying:

error[E0308]: mismatched types
  --> src/parsers/javascript/parser.rs:32:45
   |
32 |         let text_info = SourceTextInfo::new(source_text);
   |                                             ^^^^^^^^^^^ expected `str`, found `&str`
   |

I've tried casting the string, but I can only ever get it to be a &str. Any help is appreciated, I'm not sure what I'm going wrong.

@dsherret
Copy link
Member

Sorry, do SourceTextInfo::new("class MyClass {}".into()). See #103.

@nevinpuri
Copy link
Author

Thanks, that ended up fixing it.

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 a pull request may close this issue.

2 participants