Unverified Commit f628aa65 authored by hrmny's avatar hrmny Committed by GitHub

feat: support import attributes (#65749)

Co-authored-by: 's avatarC. T. Lin <chentsulin@gmail.com>
parent 0b261f09
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
"@babel/plugin-proposal-object-rest-spread": "7.20.7", "@babel/plugin-proposal-object-rest-spread": "7.20.7",
"@babel/plugin-syntax-bigint": "7.8.3", "@babel/plugin-syntax-bigint": "7.8.3",
"@babel/plugin-syntax-dynamic-import": "7.8.3", "@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-import-assertions": "7.22.5", "@babel/plugin-syntax-import-attributes": "7.22.5",
"@babel/plugin-syntax-jsx": "7.22.5", "@babel/plugin-syntax-jsx": "7.22.5",
"@babel/plugin-transform-modules-commonjs": "7.22.5", "@babel/plugin-transform-modules-commonjs": "7.22.5",
"@babel/plugin-transform-runtime": "7.22.5", "@babel/plugin-transform-runtime": "7.22.5",
......
...@@ -154,7 +154,12 @@ export default ( ...@@ -154,7 +154,12 @@ export default (
}, },
], ],
require('next/dist/compiled/babel/plugin-syntax-dynamic-import'), require('next/dist/compiled/babel/plugin-syntax-dynamic-import'),
require('next/dist/compiled/babel/plugin-syntax-import-assertions'), [
require('next/dist/compiled/babel/plugin-syntax-import-attributes'),
{
deprecatedAssertSyntax: true,
},
],
require('./plugins/react-loadable-plugin'), require('./plugins/react-loadable-plugin'),
[ [
require('next/dist/compiled/babel/plugin-proposal-class-properties'), require('next/dist/compiled/babel/plugin-proposal-class-properties'),
......
...@@ -72,8 +72,8 @@ function pluginSyntaxDynamicImport() { ...@@ -72,8 +72,8 @@ function pluginSyntaxDynamicImport() {
return require('next/dist/compiled/babel-packages').pluginSyntaxDynamicImport() return require('next/dist/compiled/babel-packages').pluginSyntaxDynamicImport()
} }
function pluginSyntaxImportAssertions() { function pluginSyntaxImportAttributes() {
return require('next/dist/compiled/babel-packages').pluginSyntaxImportAssertions() return require('next/dist/compiled/babel-packages').pluginSyntaxImportAttributes()
} }
function pluginSyntaxJsx() { function pluginSyntaxJsx() {
...@@ -127,7 +127,7 @@ module.exports = { ...@@ -127,7 +127,7 @@ module.exports = {
pluginProposalObjectRestSpread, pluginProposalObjectRestSpread,
pluginSyntaxBigint, pluginSyntaxBigint,
pluginSyntaxDynamicImport, pluginSyntaxDynamicImport,
pluginSyntaxImportAssertions, pluginSyntaxImportAttributes,
pluginSyntaxJsx, pluginSyntaxJsx,
pluginTransformDefine, pluginTransformDefine,
pluginTransformModulesCommonjs, pluginTransformModulesCommonjs,
......
...@@ -28,8 +28,8 @@ function pluginSyntaxDynamicImport() { ...@@ -28,8 +28,8 @@ function pluginSyntaxDynamicImport() {
return require('@babel/plugin-syntax-dynamic-import') return require('@babel/plugin-syntax-dynamic-import')
} }
function pluginSyntaxImportAssertions() { function pluginSyntaxImportAttributes() {
return require('@babel/plugin-syntax-import-assertions') return require('@babel/plugin-syntax-import-attributes')
} }
function pluginSyntaxJsx() { function pluginSyntaxJsx() {
...@@ -72,7 +72,7 @@ module.exports = { ...@@ -72,7 +72,7 @@ module.exports = {
pluginProposalObjectRestSpread, pluginProposalObjectRestSpread,
pluginSyntaxBigint, pluginSyntaxBigint,
pluginSyntaxDynamicImport, pluginSyntaxDynamicImport,
pluginSyntaxImportAssertions, pluginSyntaxImportAttributes,
pluginSyntaxJsx, pluginSyntaxJsx,
pluginTransformDefine, pluginTransformDefine,
pluginTransformModulesCommonjs, pluginTransformModulesCommonjs,
......
module.exports = require('./bundle').pluginSyntaxImportAssertions()
module.exports = require('./bundle').pluginSyntaxImportAttributes()
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
module.exports = require('./bundle').pluginSyntaxImportAssertions()
module.exports = require('./bundle').pluginSyntaxImportAttributes()
...@@ -877,7 +877,7 @@ importers: ...@@ -877,7 +877,7 @@ importers:
'@babel/plugin-syntax-dynamic-import': '@babel/plugin-syntax-dynamic-import':
specifier: 7.8.3 specifier: 7.8.3
version: 7.8.3(@babel/core@7.22.5) version: 7.8.3(@babel/core@7.22.5)
'@babel/plugin-syntax-import-assertions': '@babel/plugin-syntax-import-attributes':
specifier: 7.22.5 specifier: 7.22.5
version: 7.22.5(@babel/core@7.22.5) version: 7.22.5(@babel/core@7.22.5)
'@babel/plugin-syntax-jsx': '@babel/plugin-syntax-jsx':
...@@ -2114,7 +2114,7 @@ packages: ...@@ -2114,7 +2114,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
dev: true dev: true
/@babel/plugin-proposal-class-properties@7.12.1(@babel/core@7.22.5): /@babel/plugin-proposal-class-properties@7.12.1(@babel/core@7.22.5):
...@@ -2125,7 +2125,7 @@ packages: ...@@ -2125,7 +2125,7 @@ packages:
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-create-class-features-plugin': 7.22.1(@babel/core@7.22.5) '@babel/helper-create-class-features-plugin': 7.22.1(@babel/core@7.22.5)
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
dev: true dev: true
...@@ -2198,6 +2198,7 @@ packages: ...@@ -2198,6 +2198,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.22.5 '@babel/helper-plugin-utils': 7.22.5
'@babel/plugin-syntax-logical-assignment-operators': 7.10.4(@babel/core@7.22.5) '@babel/plugin-syntax-logical-assignment-operators': 7.10.4(@babel/core@7.22.5)
'@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3(@babel/core@7.22.5)
/@babel/plugin-proposal-nullish-coalescing-operator@7.16.7(@babel/core@7.22.5): /@babel/plugin-proposal-nullish-coalescing-operator@7.16.7(@babel/core@7.22.5):
resolution: {integrity: sha512-aUOrYU3EVtjf62jQrCj63pYZ7k6vns2h/DQvHPWGmsJRYzWXZ6/AsfgpiRy6XiuIDADhJzP2Q9MwSMKauBQ+UQ==} resolution: {integrity: sha512-aUOrYU3EVtjf62jQrCj63pYZ7k6vns2h/DQvHPWGmsJRYzWXZ6/AsfgpiRy6XiuIDADhJzP2Q9MwSMKauBQ+UQ==}
...@@ -2351,7 +2352,7 @@ packages: ...@@ -2351,7 +2352,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
/@babel/plugin-syntax-flow@7.16.7(@babel/core@7.22.5): /@babel/plugin-syntax-flow@7.16.7(@babel/core@7.22.5):
resolution: {integrity: sha512-UDo3YGQO0jH6ytzVwgSLv9i/CzMcUjbKenL67dTrAZPPv6GFAtDhe6jqnvmoKzC/7htNTohhos+onPtDMqJwaQ==} resolution: {integrity: sha512-UDo3YGQO0jH6ytzVwgSLv9i/CzMcUjbKenL67dTrAZPPv6GFAtDhe6jqnvmoKzC/7htNTohhos+onPtDMqJwaQ==}
...@@ -2360,7 +2361,7 @@ packages: ...@@ -2360,7 +2361,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
/@babel/plugin-syntax-flow@7.22.5(@babel/core@7.22.5): /@babel/plugin-syntax-flow@7.22.5(@babel/core@7.22.5):
resolution: {integrity: sha512-9RdCl0i+q0QExayk2nOS7853w08yLucnnPML6EN9S8fgMPVtdLDCdx/cOQ/i44Lb9UeQX9A35yaqBBOMMZxPxQ==} resolution: {integrity: sha512-9RdCl0i+q0QExayk2nOS7853w08yLucnnPML6EN9S8fgMPVtdLDCdx/cOQ/i44Lb9UeQX9A35yaqBBOMMZxPxQ==}
...@@ -2437,7 +2438,7 @@ packages: ...@@ -2437,7 +2438,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
/@babel/plugin-syntax-object-rest-spread@7.8.3(@babel/core@7.22.5): /@babel/plugin-syntax-object-rest-spread@7.8.3(@babel/core@7.22.5):
resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==} resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==}
...@@ -2445,7 +2446,7 @@ packages: ...@@ -2445,7 +2446,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
/@babel/plugin-syntax-optional-catch-binding@7.8.3(@babel/core@7.22.5): /@babel/plugin-syntax-optional-catch-binding@7.8.3(@babel/core@7.22.5):
resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==} resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==}
...@@ -2461,7 +2462,7 @@ packages: ...@@ -2461,7 +2462,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
/@babel/plugin-syntax-private-property-in-object@7.14.5(@babel/core@7.22.5): /@babel/plugin-syntax-private-property-in-object@7.14.5(@babel/core@7.22.5):
resolution: {integrity: sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==} resolution: {integrity: sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==}
...@@ -2663,7 +2664,7 @@ packages: ...@@ -2663,7 +2664,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
'@babel/plugin-syntax-flow': 7.16.7(@babel/core@7.22.5) '@babel/plugin-syntax-flow': 7.16.7(@babel/core@7.22.5)
/@babel/plugin-transform-flow-strip-types@7.22.5(@babel/core@7.22.5): /@babel/plugin-transform-flow-strip-types@7.22.5(@babel/core@7.22.5):
...@@ -2889,7 +2890,7 @@ packages: ...@@ -2889,7 +2890,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
dev: true dev: true
/@babel/plugin-transform-private-methods@7.22.5(@babel/core@7.22.5): /@babel/plugin-transform-private-methods@7.22.5(@babel/core@7.22.5):
...@@ -2930,7 +2931,7 @@ packages: ...@@ -2930,7 +2931,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
dev: true dev: true
/@babel/plugin-transform-react-display-name@7.22.5(@babel/core@7.22.5): /@babel/plugin-transform-react-display-name@7.22.5(@babel/core@7.22.5):
...@@ -2962,7 +2963,7 @@ packages: ...@@ -2962,7 +2963,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-annotate-as-pure': 7.16.7 '@babel/helper-annotate-as-pure': 7.16.7
'@babel/helper-module-imports': 7.21.4 '@babel/helper-module-imports': 7.21.4
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
'@babel/plugin-syntax-jsx': 7.22.5(@babel/core@7.22.5) '@babel/plugin-syntax-jsx': 7.22.5(@babel/core@7.22.5)
'@babel/types': 7.22.5 '@babel/types': 7.22.5
dev: true dev: true
...@@ -3012,7 +3013,7 @@ packages: ...@@ -3012,7 +3013,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
regenerator-transform: 0.15.0 regenerator-transform: 0.15.0
dev: true dev: true
...@@ -3246,7 +3247,7 @@ packages: ...@@ -3246,7 +3247,7 @@ packages:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
dependencies: dependencies:
'@babel/core': 7.22.5 '@babel/core': 7.22.5
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
'@babel/helper-validator-option': 7.21.0 '@babel/helper-validator-option': 7.21.0
'@babel/plugin-transform-flow-strip-types': 7.16.7(@babel/core@7.22.5) '@babel/plugin-transform-flow-strip-types': 7.16.7(@babel/core@7.22.5)
...@@ -8728,7 +8729,7 @@ packages: ...@@ -8728,7 +8729,7 @@ packages:
resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==} resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==}
engines: {node: '>=8'} engines: {node: '>=8'}
dependencies: dependencies:
'@babel/helper-plugin-utils': 7.21.5 '@babel/helper-plugin-utils': 7.22.5
'@istanbuljs/load-nyc-config': 1.0.0 '@istanbuljs/load-nyc-config': 1.0.0
'@istanbuljs/schema': 0.1.2 '@istanbuljs/schema': 0.1.2
istanbul-lib-instrument: 5.2.0 istanbul-lib-instrument: 5.2.0
......
...@@ -7,8 +7,10 @@ function basic(context) { ...@@ -7,8 +7,10 @@ function basic(context) {
it('should handle json assertions', async () => { it('should handle json assertions', async () => {
const esHtml = await renderViaHTTP(context.appPort, '/es') const esHtml = await renderViaHTTP(context.appPort, '/es')
const tsHtml = await renderViaHTTP(context.appPort, '/ts') const tsHtml = await renderViaHTTP(context.appPort, '/ts')
expect(esHtml).toContain('foo') // checking json value `foo` is not suffecient, since parse error
expect(tsHtml).toContain('foo') // will include code stack include those values as source
expect(esHtml).toContain(`<div id="__next">foo</div>`)
expect(tsHtml).toContain(`<div id="__next">foo</div>`)
}) })
} }
......
declare const data: any
export default data
import data from '../data' with { type: 'json' }
export default function Es() {
return data.foo
}
import data from '../data' with { type: 'json' }
export default function Ts() {
return data.foo
}
import { join } from 'path'
import { renderViaHTTP, runDevSuite, runProdSuite } from 'next-test-utils'
const appDir = join(__dirname, '../')
function basic(context) {
it('should handle json attributes', async () => {
const esHtml = await renderViaHTTP(context.appPort, '/es')
const tsHtml = await renderViaHTTP(context.appPort, '/ts')
// checking json value `foo` is not suffecient, since parse error
// will include code stack include those values as source
expect(esHtml).toContain(`<div id="__next">foo</div>`)
expect(tsHtml).toContain(`<div id="__next">foo</div>`)
})
}
runDevSuite('import-attributes', appDir, { runTests: basic })
runProdSuite('import-attributes', appDir, { runTests: basic })
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": ["node_modules"],
"include": ["**/*.d.ts", "**/*.ts", "**/*.tsx"]
}
...@@ -11339,14 +11339,25 @@ ...@@ -11339,14 +11339,25 @@
"runtimeError": false "runtimeError": false
}, },
"test/integration/import-assertion/test/index.test.js": { "test/integration/import-assertion/test/index.test.js": {
"passed": ["import-assertion dev should handle json assertions"], "passed": [],
"failed": [ "failed": [
"import-assertion dev should handle json assertions",
"production mode import-assertion prod should handle json assertions" "production mode import-assertion prod should handle json assertions"
], ],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/integration/import-attributes/test/index.test.js": {
"passed": [],
"failed": [
"import-attributes dev should handle json attributes",
"production mode import-attributes prod should handle json attributes"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/integration/index-index/test/index.test.js": { "test/integration/index-index/test/index.test.js": {
"passed": [ "passed": [
"nested index.js production mode should 404 on /index/index/index", "nested index.js production mode should 404 on /index/index/index",
...@@ -13426,11 +13426,22 @@ ...@@ -13426,11 +13426,22 @@
"runtimeError": false "runtimeError": false
}, },
"test/integration/import-assertion/test/index.test.js": { "test/integration/import-assertion/test/index.test.js": {
"passed": ["import-assertion dev should handle json assertions"], "passed": [],
"failed": [], "failed": [
"pending": [ "import-assertion dev should handle json assertions",
"production mode import-assertion prod should handle json assertions" "production mode import-assertion prod should handle json assertions"
], ],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/integration/import-attributes/test/index.test.js": {
"passed": [],
"failed": [
"import-attributes dev should handle json attributes",
"production mode import-attributes prod should handle json attributes"
],
"pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment