Module genco::lang::js

source ·
Expand description

Specialization for JavaScript code generation.

Examples

Basic example:

use genco::prelude::*;

let toks: js::Tokens = quote! {
    function foo(v) {
        return v + ", World";
    }

    foo("Hello");
};

assert_eq!(
    vec![
        "function foo(v) {",
        "    return v + \", World\";",
        "}",
        "",
        "foo(\"Hello\");",
    ],
    toks.to_file_vec()?
);

String Quoting in JavaScript

JavaScript uses c-style string quoting, with indefinitely long unicode escape sequences. But any non-control character can be embedded directly into the string literal (like "😊").

use genco::prelude::*;

let toks: js::Tokens = quote!("start π 😊 \n \x7f ÿ $ \\ end");
assert_eq!("\"start π 😊 \\n \\x7f ÿ $ \\\\ end\"", toks.to_string()?);

let toks: js::Tokens = quote!($(quoted("start π 😊 \n \x7f ÿ $ \\ end")));
assert_eq!("\"start π 😊 \\n \\x7f ÿ $ \\\\ end\"", toks.to_string()?);

Structs

  • Configuration for JavaScript.
  • Format state for JavaScript.
  • The import of a JavaScript type import {foo} from "module.js".
  • JavaScript language specialization.

Enums

  • A type-erased language item capable of holding any kind.
  • A module being imported.

Functions

  • The import of a JavaScript type import {foo} from "module.js".

Type Aliases

  • Tokens container specialization for Rust.