|
| 1 | +//// [tests/cases/conformance/es2019/importMeta/importMetaES5.ts] //// |
| 2 | + |
| 3 | +//// [example.ts] |
| 4 | +// Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example |
| 5 | +(async () => { |
| 6 | + const response = await fetch(new URL("../hamsters.jpg", import.meta.url).toString()); |
| 7 | + const blob = await response.blob(); |
| 8 | + |
| 9 | + const size = import.meta.scriptElement.dataset.size || 300; |
| 10 | + |
| 11 | + const image = new Image(); |
| 12 | + image.src = URL.createObjectURL(blob); |
| 13 | + image.width = image.height = size; |
| 14 | + |
| 15 | + document.body.appendChild(image); |
| 16 | +})(); |
| 17 | + |
| 18 | +//// [moduleLookingFile01.ts] |
| 19 | +export let x = import.meta; |
| 20 | +export let y = import.metal; |
| 21 | +export let z = import.import.import.malkovich; |
| 22 | + |
| 23 | +//// [scriptLookingFile01.ts] |
| 24 | +let globalA = import.meta; |
| 25 | +let globalB = import.metal; |
| 26 | +let globalC = import.import.import.malkovich; |
| 27 | + |
| 28 | +//// [assignmentTargets.ts] |
| 29 | +export const foo: ImportMeta = import.meta.blah = import.meta.blue = import.meta; |
| 30 | +import.meta = foo; |
| 31 | + |
| 32 | +// @Filename augmentations.ts |
| 33 | +declare global { |
| 34 | + interface ImportMeta { |
| 35 | + wellKnownProperty: { a: number, b: string, c: boolean }; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +const { a, b, c } = import.meta.wellKnownProperty; |
| 40 | + |
| 41 | +//// [example.js] |
| 42 | +"use strict"; |
| 43 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 44 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 45 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 46 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 47 | + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } |
| 48 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 49 | + }); |
| 50 | +}; |
| 51 | +var __generator = (this && this.__generator) || function (thisArg, body) { |
| 52 | + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; |
| 53 | + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
| 54 | + function verb(n) { return function (v) { return step([n, v]); }; } |
| 55 | + function step(op) { |
| 56 | + if (f) throw new TypeError("Generator is already executing."); |
| 57 | + while (_) try { |
| 58 | + if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; |
| 59 | + if (y = 0, t) op = [0, t.value]; |
| 60 | + switch (op[0]) { |
| 61 | + case 0: case 1: t = op; break; |
| 62 | + case 4: _.label++; return { value: op[1], done: false }; |
| 63 | + case 5: _.label++; y = op[1]; op = [0]; continue; |
| 64 | + case 7: op = _.ops.pop(); _.trys.pop(); continue; |
| 65 | + default: |
| 66 | + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } |
| 67 | + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } |
| 68 | + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } |
| 69 | + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } |
| 70 | + if (t[2]) _.ops.pop(); |
| 71 | + _.trys.pop(); continue; |
| 72 | + } |
| 73 | + op = body.call(thisArg, _); |
| 74 | + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } |
| 75 | + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; |
| 76 | + } |
| 77 | +}; |
| 78 | +var _this = this; |
| 79 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 80 | +// Adapted from https://github.com/tc39/proposal-import-meta/tree/c3902a9ffe2e69a7ac42c19d7ea74cbdcea9b7fb#example |
| 81 | +(function () { return __awaiter(_this, void 0, void 0, function () { |
| 82 | + var response, blob, size, image; |
| 83 | + return __generator(this, function (_a) { |
| 84 | + switch (_a.label) { |
| 85 | + case 0: return [4 /*yield*/, fetch(new URL("../hamsters.jpg", import.meta.url).toString())]; |
| 86 | + case 1: |
| 87 | + response = _a.sent(); |
| 88 | + return [4 /*yield*/, response.blob()]; |
| 89 | + case 2: |
| 90 | + blob = _a.sent(); |
| 91 | + size = import.meta.scriptElement.dataset.size || 300; |
| 92 | + image = new Image(); |
| 93 | + image.src = URL.createObjectURL(blob); |
| 94 | + image.width = image.height = size; |
| 95 | + document.body.appendChild(image); |
| 96 | + return [2 /*return*/]; |
| 97 | + } |
| 98 | + }); |
| 99 | +}); })(); |
| 100 | +//// [moduleLookingFile01.js] |
| 101 | +"use strict"; |
| 102 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 103 | +exports.x = (import.meta); |
| 104 | +exports.y = (import.metal); |
| 105 | +exports.z = import.import.import.malkovich; |
| 106 | +//// [scriptLookingFile01.js] |
| 107 | +"use strict"; |
| 108 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 109 | +var globalA = import.meta; |
| 110 | +var globalB = import.metal; |
| 111 | +var globalC = import.import.import.malkovich; |
| 112 | +//// [assignmentTargets.js] |
| 113 | +"use strict"; |
| 114 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 115 | +exports.foo = import.meta.blah = import.meta.blue = import.meta; |
| 116 | +import.meta = exports.foo; |
| 117 | +var _a = import.meta.wellKnownProperty, a = _a.a, b = _a.b, c = _a.c; |
0 commit comments