8000 Support 'import.meta' by DanielRosenwasser · Pull Request #23327 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Support 'import.meta' #23327

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

Merged
merged 16 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests around ES5, assigning to 'import.meta' and properties, gl…
…obal augmentations.
  • Loading branch information
DanielRosenwasser committed Apr 10, 2018
commit 4f497e6c0c250d68af4ae9045922eace82d3750f
13 changes: 13 additions & 0 deletions tests/cases/conformance/es2019/importMeta/importMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ export let z = import.import.import.malkovich;
let globalA = import.meta;
let globalB = import.metal;
let globalC = import.import.import.malkovich;

// @Filename: assignmentTargets.ts
export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta;
import.meta = foo;

// @Filename augmentations.ts
declare global {
interface ImportMeta {
wellKnownProperty: { a: number, b: string, c: boolean };
}
}

const { a, b, c } = import.meta.wellKnownProperty;
42 changes: 42 additions & 0 deletions tests/cases/conformance/es2019/importMeta/importMetaES5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

// @target: es5
// @module: commonjs
// @lib: es5,dom

// @Filename: example.ts
// Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example
(async () => {
const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString());
const blob = await response.blob();

const size = import.meta.scriptElement.dataset.size || 300;

const image = new Image();
image.src = URL.createObjectURL(blob);
image.width = image.height = size;

document.body.appendChild(image);
})();

// @Filename: moduleLookingFile01.ts
export let x = import.meta;
export let y = import.metal;
export let z = import.import.import.malkovich;

// @Filename: scriptLookingFile01.ts
let globalA = import.meta;
let globalB = import.metal;
let globalC = import.import.import.malkovich;

// @Filename: assignmentTargets.ts
export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta;
import.meta = foo;

// @Filename augmentations.ts
declare global {
interface ImportMeta {
wellKnownProperty: { a: number, b: string, c: boolean };
}
}

const { a, b, c } = import.meta.wellKnownProperty;
0