| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e5b8896 commit 2c621d6
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | const { | |
| 4 | 4 | ArrayPrototypeFilter, | |
| 5 | 5 | ArrayPrototypeIncludes, | |
| 6 | + ObjectKeys, | ||
| 6 | 7 | ObjectValues, | |
| 7 | 8 | ObjectPrototypeHasOwnProperty, | |
| 8 | 9 | } = primordials; | |
@@ -17,6 +18,8 @@ const { | |||
| 17 | 18 | // The HTML spec has an implied default type of `'javascript'`. | |
| 18 | 19 | const kImplicitAssertType = 'javascript'; | |
| 19 | 20 | ||
| 21 | + let alreadyWarned = false; | ||
| 22 | + | ||
| 20 | 23 | /** | |
| 21 | 24 | * Define a map of module formats to import assertion types (the value of | |
| 22 | 25 | * `type` in `assert { type: 'json' }`). | |
@@ -55,6 +58,16 @@ function validateAssertions(url, format, | |||
| 55 | 58 | importAssertions = { __proto__: null }) { | |
| 56 | 59 | const validType = formatTypeMap[format]; | |
| 57 | 60 | ||
| 61 | + if (!alreadyWarned && ObjectKeys(importAssertions).length !== 0) { | ||
| 62 | + alreadyWarned = true; | ||
| 63 | + process.emitWarning( | ||
| 64 | + 'Import assertions are not a stable feature of the JavaScript language, ' + | ||
| 65 | + 'avoid relying on their current behavior and syntax as those might change ' + | ||
| 66 | + 'in a future version of Node.js.', | ||
| 67 | + 'ExperimentalWarning', | ||
| 68 | + ); | ||
| 69 | + } | ||
| 70 | + | ||
| 58 | 71 | switch (validType) { | |
| 59 | 72 | case undefined: | |
| 60 | 73 | // Ignore assertions for module formats we don't recognize, to allow new | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,13 @@ const { rejects } = require('assert'); | |||
| 5 | 5 | const jsModuleDataUrl = 'data:text/javascript,export{}'; | |
| 6 | 6 | const jsonModuleDataUrl = 'data:application/json,""'; | |
| 7 | 7 | ||
| 8 | + common.expectWarning( | ||
| 9 | + 'ExperimentalWarning', | ||
| 10 | + 'Import assertions are not a stable feature of the JavaScript language, ' + | ||
| 11 | + 'avoid relying on their current behavior and syntax as those might change ' + | ||
| 12 | + 'in a future version of Node.js.' | ||
| 13 | + ); | ||
| 14 | + | ||
| 8 | 15 | async function test() { | |
| 9 | 16 | await rejects( | |
| 10 | 17 | import('data:text/css,', { assert: { type: 'css' } }), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,17 @@ | |||
| 1 | - import '../common/index.mjs'; | ||
| 1 | + import { expectWarning } from '../common/index.mjs'; | ||
| 2 | 2 | import { rejects } from 'assert'; | |
| 3 | 3 | ||
| 4 | 4 | const jsModuleDataUrl = 'data:text/javascript,export{}'; | |
| 5 | 5 | const jsonModuleDataUrl = 'data:application/json,""'; | |
| 6 | 6 | ||
| 7 | + expectWarning( | ||
| 8 | + 'ExperimentalWarning', | ||
| 9 | + 'Import assertions are not a stable feature of the JavaScript language, ' + | ||
| 10 | + 'avoid relying on their current behavior and syntax as those might change ' + | ||
| 11 | + 'in a future version of Node.js.' | ||
| 12 | + ); | ||
| 13 | + | ||
| 14 | + | ||
| 7 | 15 | await rejects( | |
| 8 | 16 | // This rejects because of the unsupported MIME type, not because of the | |
| 9 | 17 | // unsupported assertion. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,19 @@ | |||
| 1 | 1 | // Flags: --expose-internals | |
| 2 | 2 | 'use strict'; | |
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | ||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | ||
| 7 | 7 | const { validateAssertions } = require('internal/modules/esm/assert'); | |
| 8 | 8 | ||
| 9 | + common.expectWarning( | ||
| 10 | + 'ExperimentalWarning', | ||
| 11 | + 'Import assertions are not a stable feature of the JavaScript language, ' + | ||
| 12 | + 'avoid relying on their current behavior and syntax as those might change ' + | ||
| 13 | + 'in a future version of Node.js.' | ||
| 14 | + ); | ||
| 15 | + | ||
| 16 | + | ||
| 9 | 17 | const url = 'test://'; | |
| 10 | 18 | ||
| 11 | 19 | assert.ok(validateAssertions(url, 'builtin', {})); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + import { expectWarning } from '../common/index.mjs'; | ||
| 2 | + | ||
| 3 | + expectWarning( | ||
| 4 | + 'ExperimentalWarning', | ||
| 5 | + 'Import assertions are not a stable feature of the JavaScript language, ' + | ||
| 6 | + 'avoid relying on their current behavior and syntax as those might change ' + | ||
| 7 | + 'in a future version of Node.js.' | ||
| 8 | + ); | ||
| 9 | + | ||
| 10 | + await import('data:text/javascript,', { assert: { someUnsupportedKey: 'value' } }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ import { describe, it } from 'node:test'; | |||
| 6 | 6 | ||
| 7 | 7 | import secret from '../fixtures/experimental.json' assert { type: 'json' }; | |
| 8 | 8 | ||
| 9 | - | ||
| 10 | 9 | describe('ESM: importing JSON', () => { | |
| 11 | 10 | it('should load JSON', () => { | |
| 12 | 11 | assert.strictEqual(secret.ofLife, 42); | |
@@ -17,8 +16,8 @@ describe('ESM: importing JSON', () => { | |||
| 17 | 16 | fixtures.path('/es-modules/json-modules.mjs'), | |
| 18 | 17 | ]); | |
| 19 | 18 | ||
| 20 | - assert.match(stderr, /ExperimentalWarning/); | ||
| 21 | - assert.match(stderr, /JSON modules/); | ||
| 19 | + assert.match(stderr, /ExperimentalWarning: Importing JSON modules/); | ||
| 20 | + assert.match(stderr, /ExperimentalWarning: Import assertions/); | ||
| 22 | 21 | assert.strictEqual(code, 0); | |
| 23 | 22 | assert.strictEqual(signal, null); | |
| 24 | 23 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments