Skip to content

Commit

Permalink
fix(ecmascript/codegen): TsQualifiedName has trailing dot (#1268)
Browse files Browse the repository at this point in the history
Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
  • Loading branch information
Liamolucko and kdy1 authored Dec 20, 2020
1 parent 0ead8dc commit b760c7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ecmascript/codegen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ pub(crate) fn assert_min(from: &str, to: &str) {
assert_eq!(DebugUsingDisplay(out.trim()), DebugUsingDisplay(to),);
}

/// Clone of the regular `assert_min` function but with TypeScript syntax.
pub(crate) fn assert_min_typescript(from: &str, to: &str) {
let out = parse_then_emit(
from,
Config { minify: true },
Syntax::Typescript(Default::default()),
);

assert_eq!(DebugUsingDisplay(out.trim()), DebugUsingDisplay(to),);
}

pub(crate) fn assert_pretty(from: &str, to: &str) {
let out = parse_then_emit(from, Config { minify: false }, Syntax::default());

Expand Down
14 changes: 13 additions & 1 deletion ecmascript/codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl<'a> Emitter<'a> {
match n {
TsEntityName::TsQualifiedName(n) => {
emit!(n);
punct!(".");
}
TsEntityName::Ident(n) => emit!(n),
}
Expand Down Expand Up @@ -973,3 +972,16 @@ impl<'a> Emitter<'a> {
self.emit_list(n.span, Some(&n.types), ListFormat::UnionTypeConstituents)?;
}
}

#[cfg(test)]
mod tests {
use crate::tests::assert_min_typescript;

#[test]
fn qualified_type() {
assert_min_typescript(
"var memory: WebAssembly.Memory;",
"var memory:WebAssembly.Memory;",
);
}
}

0 comments on commit b760c7c

Please sign in to comment.