2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-07-28 15:08:13 -04:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertEquals,
|
2021-12-08 19:12:14 -05:00
|
|
|
assertRejects,
|
2021-05-19 00:18:01 -04:00
|
|
|
assertStringIncludes,
|
2021-08-11 10:20:47 -04:00
|
|
|
} from "../../../test_util/std/testing/asserts.ts";
|
2020-01-08 09:17:44 -05:00
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - sources provided",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"/foo.ts",
|
|
|
|
{
|
|
|
|
sources: {
|
|
|
|
"/foo.ts": `import * as bar from "./bar.ts";\n\nconsole.log(bar);\n`,
|
|
|
|
"/bar.ts": `export const bar = "bar";\n`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
2020-11-01 21:51:56 -05:00
|
|
|
assert(keys[0].endsWith("/bar.ts.js"));
|
|
|
|
assert(keys[1].endsWith("/bar.ts.js.map"));
|
|
|
|
assert(keys[2].endsWith("/foo.ts.js"));
|
|
|
|
assert(keys[3].endsWith("/foo.ts.js.map"));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - no sources provided",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"./subdir/mod1.ts",
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
2020-06-18 09:06:48 -04:00
|
|
|
assertEquals(keys.length, 6);
|
2021-08-11 10:20:47 -04:00
|
|
|
assert(keys[0].endsWith("subdir/mod1.ts.js"));
|
|
|
|
assert(keys[1].endsWith("subdir/mod1.ts.js.map"));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - compiler options effects emit",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
2020-06-18 09:06:48 -04:00
|
|
|
"/foo.ts",
|
|
|
|
{
|
2020-12-31 16:43:54 -05:00
|
|
|
compilerOptions: {
|
|
|
|
module: "amd",
|
|
|
|
sourceMap: false,
|
|
|
|
},
|
|
|
|
sources: { "/foo.ts": `export const foo = "foo";` },
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-18 09:06:48 -04:00
|
|
|
);
|
2020-12-31 16:43:54 -05:00
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files);
|
2020-11-01 21:51:56 -05:00
|
|
|
assertEquals(keys.length, 1);
|
|
|
|
const key = keys[0];
|
|
|
|
assert(key.endsWith("/foo.ts.js"));
|
2020-12-31 16:43:54 -05:00
|
|
|
assert(files[key].startsWith("define("));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - pass lib in compiler options",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
2020-11-01 21:51:56 -05:00
|
|
|
"file:///foo.ts",
|
2020-06-18 09:06:48 -04:00
|
|
|
{
|
2020-12-31 16:43:54 -05:00
|
|
|
compilerOptions: {
|
|
|
|
lib: ["dom", "es2018", "deno.ns"],
|
|
|
|
},
|
|
|
|
sources: {
|
|
|
|
"file:///foo.ts": `console.log(document.getElementById("foo"));
|
|
|
|
console.log(Deno.args);`,
|
|
|
|
},
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-12-31 16:43:54 -05:00
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assertEquals(keys, ["file:///foo.ts.js", "file:///foo.ts.js.map"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-21 17:18:32 -04:00
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - type references can be loaded",
|
|
|
|
async fn() {
|
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"file:///a.ts",
|
|
|
|
{
|
|
|
|
sources: {
|
|
|
|
"file:///a.ts": `/// <reference types="./b.d.ts" />
|
|
|
|
const b = new B();
|
|
|
|
console.log(b.b);`,
|
|
|
|
"file:///b.d.ts": `declare class B {
|
|
|
|
b: string;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - compilerOptions.types",
|
|
|
|
async fn() {
|
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"file:///a.ts",
|
|
|
|
{
|
|
|
|
compilerOptions: {
|
|
|
|
types: ["file:///b.d.ts"],
|
|
|
|
},
|
|
|
|
sources: {
|
|
|
|
"file:///a.ts": `const b = new B();
|
|
|
|
console.log(b.b);`,
|
|
|
|
"file:///b.d.ts": `declare class B {
|
|
|
|
b: string;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-31 16:43:54 -05:00
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - import maps",
|
|
|
|
async fn() {
|
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"file:///a.ts",
|
2020-06-18 09:06:48 -04:00
|
|
|
{
|
2020-12-31 16:43:54 -05:00
|
|
|
importMap: {
|
|
|
|
imports: {
|
|
|
|
"b": "./b.ts",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
importMapPath: "file:///import-map.json",
|
|
|
|
sources: {
|
|
|
|
"file:///a.ts": `import * as b from "b"
|
|
|
|
console.log(b);`,
|
|
|
|
"file:///b.ts": `export const b = "b";`,
|
|
|
|
},
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-18 09:06:48 -04:00
|
|
|
);
|
2020-12-31 16:43:54 -05:00
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
|
|
|
const keys = Object.keys(files).sort();
|
2020-11-01 21:51:56 -05:00
|
|
|
assertEquals(
|
2020-12-31 16:43:54 -05:00
|
|
|
keys,
|
|
|
|
[
|
|
|
|
"file:///a.ts.js",
|
|
|
|
"file:///a.ts.js.map",
|
|
|
|
"file:///b.ts.js",
|
|
|
|
"file:///b.ts.js.map",
|
|
|
|
],
|
2020-09-09 07:37:22 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-14 06:13:15 -04:00
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - allowSyntheticDefaultImports true by default",
|
|
|
|
async fn() {
|
|
|
|
const { diagnostics, files, ignoredOptions } = await Deno.emit(
|
|
|
|
"file:///a.ts",
|
|
|
|
{
|
|
|
|
sources: {
|
|
|
|
"file:///a.ts": `import b from "./b.js";\n`,
|
|
|
|
"file:///b.js":
|
|
|
|
`/// <reference types="./b.d.ts";\n\nconst b = "b";\n\nexport default b;\n`,
|
|
|
|
"file:///b.d.ts": `declare const b: "b";\nexport = b;\n`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assertEquals(keys, [
|
|
|
|
"file:///a.ts.js",
|
|
|
|
"file:///a.ts.js.map",
|
|
|
|
"file:///b.js",
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - no check",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"/foo.ts",
|
|
|
|
{
|
|
|
|
check: false,
|
|
|
|
sources: {
|
|
|
|
"/foo.ts": `export enum Foo { Foo, Bar, Baz };\n`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 3);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assert(keys[0].endsWith("/foo.ts.js"));
|
|
|
|
assert(keys[1].endsWith("/foo.ts.js.map"));
|
|
|
|
assert(files[keys[0]].startsWith("export var Foo;"));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - no check - config effects emit",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"/foo.ts",
|
2020-06-18 09:06:48 -04:00
|
|
|
{
|
2020-12-31 16:43:54 -05:00
|
|
|
check: false,
|
|
|
|
compilerOptions: { removeComments: true },
|
|
|
|
sources: {
|
|
|
|
"/foo.ts":
|
|
|
|
`/** This is JSDoc */\nexport enum Foo { Foo, Bar, Baz };\n`,
|
|
|
|
},
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-18 09:06:48 -04:00
|
|
|
);
|
2020-12-31 16:43:54 -05:00
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 3);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assert(keys[0].endsWith("/foo.ts.js"));
|
|
|
|
assert(keys[1].endsWith("/foo.ts.js.map"));
|
|
|
|
assert(!files[keys[0]].includes("This is JSDoc"));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2021-04-25 16:54:57 -04:00
|
|
|
name: "Deno.emit() - bundle as module script - with sources",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"/foo.ts",
|
|
|
|
{
|
2021-04-25 16:54:57 -04:00
|
|
|
bundle: "module",
|
2020-12-31 16:43:54 -05:00
|
|
|
sources: {
|
|
|
|
"/foo.ts": `export * from "./bar.ts";\n`,
|
|
|
|
"/bar.ts": `export const bar = "bar";\n`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
2021-05-19 00:18:01 -04:00
|
|
|
assertEquals(
|
|
|
|
Object.keys(files).sort(),
|
|
|
|
["deno:///bundle.js", "deno:///bundle.js.map"].sort(),
|
|
|
|
);
|
2021-12-08 19:12:14 -05:00
|
|
|
assert(files["deno:///bundle.js"].includes(`const bar = "bar"`));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-01-08 09:17:44 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2021-04-25 16:54:57 -04:00
|
|
|
name: "Deno.emit() - bundle as module script - no sources",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"./subdir/mod1.ts",
|
|
|
|
{
|
2021-04-25 16:54:57 -04:00
|
|
|
bundle: "module",
|
2020-12-31 16:43:54 -05:00
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
|
|
|
assertEquals(stats.length, 12);
|
2021-05-19 00:18:01 -04:00
|
|
|
assertEquals(
|
|
|
|
Object.keys(files).sort(),
|
|
|
|
["deno:///bundle.js", "deno:///bundle.js.map"].sort(),
|
|
|
|
);
|
2020-12-31 16:43:54 -05:00
|
|
|
assert(files["deno:///bundle.js"].length);
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
2021-04-25 16:54:57 -04:00
|
|
|
name: "Deno.emit() - bundle as module script - include js modules",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
|
|
|
|
"/foo.js",
|
|
|
|
{
|
2021-04-25 16:54:57 -04:00
|
|
|
bundle: "module",
|
2020-12-31 16:43:54 -05:00
|
|
|
sources: {
|
|
|
|
"/foo.js": `export * from "./bar.js";\n`,
|
|
|
|
"/bar.js": `export const bar = "bar";\n`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assert(!ignoredOptions);
|
2021-12-16 05:45:41 -05:00
|
|
|
assertEquals(stats.length, 0);
|
2021-05-19 00:18:01 -04:00
|
|
|
assertEquals(
|
|
|
|
Object.keys(files).sort(),
|
|
|
|
["deno:///bundle.js.map", "deno:///bundle.js"].sort(),
|
|
|
|
);
|
2021-12-08 19:12:14 -05:00
|
|
|
assert(files["deno:///bundle.js"].includes(`const bar = "bar"`));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-03-02 16:18:27 -05:00
|
|
|
});
|
|
|
|
|
2020-06-18 09:06:48 -04:00
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - generates diagnostics",
|
2020-06-18 09:06:48 -04:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics, files } = await Deno.emit(
|
|
|
|
"/foo.ts",
|
|
|
|
{
|
|
|
|
sources: {
|
|
|
|
"/foo.ts": `document.getElementById("foo");`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assertEquals(diagnostics.length, 1);
|
|
|
|
const keys = Object.keys(files).sort();
|
|
|
|
assert(keys[0].endsWith("/foo.ts.js"));
|
|
|
|
assert(keys[1].endsWith("/foo.ts.js.map"));
|
2020-06-18 09:06:48 -04:00
|
|
|
},
|
2020-02-07 01:54:05 -05:00
|
|
|
});
|
2020-07-28 15:08:13 -04:00
|
|
|
|
|
|
|
// See https://github.com/denoland/deno/issues/6908
|
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: "Deno.emit() - invalid syntax does not panic",
|
2020-07-28 15:08:13 -04:00
|
|
|
async fn() {
|
2021-10-10 17:26:22 -04:00
|
|
|
const { diagnostics } = await Deno.emit("/main.js", {
|
|
|
|
sources: {
|
|
|
|
"/main.js": `
|
2020-12-31 16:43:54 -05:00
|
|
|
export class Foo {
|
|
|
|
constructor() {
|
|
|
|
console.log("foo");
|
|
|
|
}
|
|
|
|
export get() {
|
|
|
|
console.log("bar");
|
|
|
|
}
|
|
|
|
}`,
|
2021-10-10 17:26:22 -04:00
|
|
|
},
|
2020-07-28 15:08:13 -04:00
|
|
|
});
|
2021-10-10 17:26:22 -04:00
|
|
|
assertEquals(diagnostics.length, 1);
|
|
|
|
assert(
|
|
|
|
diagnostics[0].messageText!.startsWith(
|
|
|
|
"The module's source code could not be parsed: Unexpected token `get`. Expected * for generator, private key, identifier or async at file:",
|
|
|
|
),
|
|
|
|
);
|
2020-07-28 15:08:13 -04:00
|
|
|
},
|
|
|
|
});
|
2020-11-09 14:50:33 -05:00
|
|
|
|
|
|
|
Deno.test({
|
2020-12-31 16:43:54 -05:00
|
|
|
name: 'Deno.emit() - allows setting of "importsNotUsedAsValues"',
|
2020-11-09 14:50:33 -05:00
|
|
|
async fn() {
|
2020-12-31 16:43:54 -05:00
|
|
|
const { diagnostics } = await Deno.emit("/a.ts", {
|
|
|
|
sources: {
|
|
|
|
"/a.ts": `import { B } from "./b.ts";
|
|
|
|
const b: B = { b: "b" };`,
|
|
|
|
"/b.ts": `export interface B {
|
|
|
|
b:string;
|
|
|
|
};`,
|
|
|
|
},
|
|
|
|
compilerOptions: {
|
|
|
|
importsNotUsedAsValues: "error",
|
|
|
|
},
|
2020-11-09 14:50:33 -05:00
|
|
|
});
|
|
|
|
assert(diagnostics);
|
|
|
|
assertEquals(diagnostics.length, 1);
|
|
|
|
assert(diagnostics[0].messageText);
|
|
|
|
assert(diagnostics[0].messageText.includes("This import is never used"));
|
|
|
|
},
|
|
|
|
});
|
2021-01-28 20:33:58 -05:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - Unknown media type does not panic",
|
|
|
|
async fn() {
|
2021-10-10 17:26:22 -04:00
|
|
|
await Deno.emit("https://example.com/foo", {
|
|
|
|
sources: {
|
|
|
|
"https://example.com/foo": `let foo: string = "foo";`,
|
|
|
|
},
|
2021-01-28 20:33:58 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2021-02-01 03:02:02 -05:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - non-normalized specifier and source can compile",
|
|
|
|
async fn() {
|
|
|
|
const specifier = "https://example.com/foo//bar.ts";
|
|
|
|
const { files } = await Deno.emit(specifier, {
|
|
|
|
sources: {
|
|
|
|
[specifier]: `export let foo: string = "foo";`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assertEquals(files[`${specifier}.js`], 'export let foo = "foo";\n');
|
|
|
|
assert(typeof files[`${specifier}.js.map`] === "string");
|
|
|
|
},
|
|
|
|
});
|
2021-02-15 20:02:00 -05:00
|
|
|
|
|
|
|
Deno.test({
|
2021-04-25 16:54:57 -04:00
|
|
|
name: `Deno.emit() - bundle as classic script iife`,
|
2021-02-15 20:02:00 -05:00
|
|
|
async fn() {
|
|
|
|
const { diagnostics, files } = await Deno.emit("/a.ts", {
|
2021-04-25 16:54:57 -04:00
|
|
|
bundle: "classic",
|
2021-02-15 20:02:00 -05:00
|
|
|
sources: {
|
|
|
|
"/a.ts": `import { b } from "./b.ts";
|
|
|
|
console.log(b);`,
|
|
|
|
"/b.ts": `export const b = "b";`,
|
|
|
|
},
|
|
|
|
});
|
2022-01-12 07:05:06 -05:00
|
|
|
const ignoreDirecives = [
|
|
|
|
"// deno-fmt-ignore-file",
|
|
|
|
"// deno-lint-ignore-file",
|
|
|
|
"// This code was bundled using `deno bundle` and it's not recommended to edit it manually",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
].join("\n");
|
2021-02-15 20:02:00 -05:00
|
|
|
assert(diagnostics);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
2021-05-19 00:18:01 -04:00
|
|
|
assertEquals(Object.keys(files).length, 2);
|
2022-01-12 07:05:06 -05:00
|
|
|
assert(
|
|
|
|
files["deno:///bundle.js"].startsWith(
|
|
|
|
ignoreDirecives + "(function() {\n",
|
|
|
|
),
|
|
|
|
);
|
2021-02-15 20:02:00 -05:00
|
|
|
assert(files["deno:///bundle.js"].endsWith("})();\n"));
|
2021-05-19 00:18:01 -04:00
|
|
|
assert(files["deno:///bundle.js.map"]);
|
2021-02-15 20:02:00 -05:00
|
|
|
},
|
|
|
|
});
|
2021-05-04 08:27:20 -04:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: `Deno.emit() - throws descriptive error when unable to load import map`,
|
|
|
|
async fn() {
|
2021-12-08 19:12:14 -05:00
|
|
|
await assertRejects(
|
2021-05-04 08:27:20 -04:00
|
|
|
async () => {
|
|
|
|
await Deno.emit("/a.ts", {
|
|
|
|
bundle: "classic",
|
|
|
|
sources: {
|
|
|
|
"/a.ts": `console.log("hello");`,
|
|
|
|
},
|
|
|
|
importMapPath: "file:///import_map_does_not_exist.json",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
Error,
|
|
|
|
"Unable to load 'file:///import_map_does_not_exist.json' import map",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2021-05-19 00:18:01 -04:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: `Deno.emit() - support source maps with bundle option`,
|
|
|
|
async fn() {
|
|
|
|
{
|
|
|
|
const { diagnostics, files } = await Deno.emit("/a.ts", {
|
|
|
|
bundle: "classic",
|
|
|
|
sources: {
|
|
|
|
"/a.ts": `import { b } from "./b.ts";
|
|
|
|
console.log(b);`,
|
|
|
|
"/b.ts": `export const b = "b";`,
|
|
|
|
},
|
|
|
|
compilerOptions: {
|
|
|
|
inlineSourceMap: true,
|
|
|
|
sourceMap: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert(diagnostics);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assertEquals(Object.keys(files).length, 1);
|
|
|
|
assertStringIncludes(files["deno:///bundle.js"], "sourceMappingURL");
|
|
|
|
}
|
|
|
|
|
|
|
|
const { diagnostics, files } = await Deno.emit("/a.ts", {
|
|
|
|
bundle: "classic",
|
|
|
|
sources: {
|
|
|
|
"/a.ts": `import { b } from "./b.ts";
|
|
|
|
console.log(b);`,
|
|
|
|
"/b.ts": `export const b = "b";`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert(diagnostics);
|
|
|
|
assertEquals(diagnostics.length, 0);
|
|
|
|
assertEquals(Object.keys(files).length, 2);
|
|
|
|
assert(files["deno:///bundle.js"]);
|
|
|
|
assert(files["deno:///bundle.js.map"]);
|
|
|
|
},
|
|
|
|
});
|
2021-06-21 17:27:32 -04:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: `Deno.emit() - graph errors as diagnostics`,
|
|
|
|
ignore: Deno.build.os === "windows",
|
|
|
|
async fn() {
|
|
|
|
const { diagnostics } = await Deno.emit("/a.ts", {
|
|
|
|
sources: {
|
|
|
|
"/a.ts": `import { b } from "./b.ts";
|
|
|
|
console.log(b);`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
assert(diagnostics);
|
|
|
|
assertEquals(diagnostics, [
|
|
|
|
{
|
|
|
|
category: 1,
|
|
|
|
code: 2305,
|
|
|
|
start: { line: 0, character: 9 },
|
|
|
|
end: { line: 0, character: 10 },
|
|
|
|
messageText:
|
|
|
|
`Module '"deno:///missing_dependency.d.ts"' has no exported member 'b'.`,
|
|
|
|
messageChain: null,
|
|
|
|
source: null,
|
|
|
|
sourceLine: 'import { b } from "./b.ts";',
|
|
|
|
fileName: "file:///a.ts",
|
|
|
|
relatedInformation: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
category: 1,
|
|
|
|
code: 900001,
|
|
|
|
start: null,
|
|
|
|
end: null,
|
2021-12-22 08:25:06 -05:00
|
|
|
messageText: 'Module not found "file:///b.ts".',
|
2021-06-21 17:27:32 -04:00
|
|
|
messageChain: null,
|
|
|
|
source: null,
|
|
|
|
sourceLine: null,
|
|
|
|
fileName: "file:///b.ts",
|
|
|
|
relatedInformation: null,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
assert(
|
|
|
|
Deno.formatDiagnostics(diagnostics).includes(
|
2021-12-22 08:25:06 -05:00
|
|
|
'Module not found "file:///b.ts".',
|
2021-06-21 17:27:32 -04:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2021-10-27 02:18:53 -04:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - no check respects inlineSources compiler option",
|
|
|
|
async fn() {
|
|
|
|
const { files } = await Deno.emit(
|
|
|
|
"file:///a.ts",
|
|
|
|
{
|
|
|
|
check: false,
|
|
|
|
compilerOptions: {
|
|
|
|
types: ["file:///b.d.ts"],
|
|
|
|
inlineSources: true,
|
|
|
|
},
|
|
|
|
sources: {
|
|
|
|
"file:///a.ts": `const b = new B();
|
|
|
|
console.log(b.b);`,
|
|
|
|
"file:///b.d.ts": `declare class B {
|
|
|
|
b: string;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
const sourceMap: { sourcesContent?: string[] } = JSON.parse(
|
|
|
|
files["file:///a.ts.js.map"],
|
|
|
|
);
|
|
|
|
assert(sourceMap.sourcesContent);
|
|
|
|
assertEquals(sourceMap.sourcesContent.length, 1);
|
|
|
|
},
|
|
|
|
});
|
2021-11-08 20:26:39 -05:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - JSX import source pragma",
|
|
|
|
async fn() {
|
|
|
|
const { files } = await Deno.emit(
|
|
|
|
"file:///a.tsx",
|
|
|
|
{
|
|
|
|
sources: {
|
|
|
|
"file:///a.tsx": `/** @jsxImportSource https://example.com/jsx */
|
2021-12-08 19:12:14 -05:00
|
|
|
|
2021-11-08 20:26:39 -05:00
|
|
|
export function App() {
|
|
|
|
return (
|
|
|
|
<div><></></div>
|
|
|
|
);
|
|
|
|
}`,
|
|
|
|
"https://example.com/jsx/jsx-runtime": `export function jsx(
|
|
|
|
_type,
|
|
|
|
_props,
|
|
|
|
_key,
|
|
|
|
_source,
|
|
|
|
_self,
|
|
|
|
) {}
|
|
|
|
export const jsxs = jsx;
|
|
|
|
export const jsxDEV = jsx;
|
|
|
|
export const Fragment = Symbol("Fragment");
|
|
|
|
console.log("imported", import.meta.url);
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assert(files["file:///a.tsx.js"]);
|
|
|
|
assert(
|
|
|
|
files["file:///a.tsx.js"].startsWith(
|
|
|
|
`import { Fragment as _Fragment, jsx as _jsx } from "https://example.com/jsx/jsx-runtime";\n`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "Deno.emit() - JSX import source no pragma",
|
|
|
|
async fn() {
|
|
|
|
const { files } = await Deno.emit(
|
|
|
|
"file:///a.tsx",
|
|
|
|
{
|
|
|
|
compilerOptions: {
|
|
|
|
jsx: "react-jsx",
|
|
|
|
jsxImportSource: "https://example.com/jsx",
|
|
|
|
},
|
|
|
|
sources: {
|
|
|
|
"file:///a.tsx": `export function App() {
|
|
|
|
return (
|
|
|
|
<div><></></div>
|
|
|
|
);
|
|
|
|
}`,
|
|
|
|
"https://example.com/jsx/jsx-runtime": `export function jsx(
|
|
|
|
_type,
|
|
|
|
_props,
|
|
|
|
_key,
|
|
|
|
_source,
|
|
|
|
_self,
|
|
|
|
) {}
|
|
|
|
export const jsxs = jsx;
|
|
|
|
export const jsxDEV = jsx;
|
|
|
|
export const Fragment = Symbol("Fragment");
|
|
|
|
console.log("imported", import.meta.url);
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
assert(files["file:///a.tsx.js"]);
|
|
|
|
assert(
|
|
|
|
files["file:///a.tsx.js"].startsWith(
|
|
|
|
`import { Fragment as _Fragment, jsx as _jsx } from "https://example.com/jsx/jsx-runtime";\n`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|