Skip to content
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

deps: upgrade various deps (mainly babel) #20586

Merged
merged 15 commits into from Dec 29, 2020
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -39,8 +39,8 @@
"pre-commit": "lint-staged",
"devDependencies": {
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
"@babel/preset-flow": "7.10.4",
"@babel/preset-react": "7.12.5",
"@babel/preset-flow": "7.12.1",
"@babel/preset-react": "7.12.10",
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@types/cheerio": "0.22.16",
Expand Down
6 changes: 3 additions & 3 deletions packages/next-polyfill-module/package.json
Expand Up @@ -9,10 +9,10 @@
"directory": "packages/next-polyfill-module"
},
"scripts": {
"prepublish": "microbundle src/index.js -f iife --no-sourcemap --external none",
"build": "microbundle watch src/index.js -f iife --no-sourcemap --external none"
"prepublish": "microbundle -i src/index.js -o dist/polyfill-module.js -f iife --no-sourcemap --external none --no-pkg-main",
"build": "microbundle watch -i src/index.js -o dist/polyfill-module.js -f iife --no-sourcemap --external none --no-pkg-main"
},
"devDependencies": {
"microbundle": "0.11.0"
"microbundle": "0.13.0"
}
}
6 changes: 3 additions & 3 deletions packages/next-polyfill-nomodule/package.json
Expand Up @@ -9,12 +9,12 @@
"directory": "packages/next-polyfill-nomodule"
},
"scripts": {
"prepublish": "microbundle src/index.js -f iife --no-sourcemap --external none",
"build": "microbundle watch src/index.js -f iife --no-sourcemap --external none"
"prepublish": "microbundle -i src/index.js -o dist/polyfill-nomodule.js -f iife --no-sourcemap --external none --no-pkg-main",
"build": "microbundle watch -i src/index.js -o dist/polyfill-nomodule.js -f iife --no-sourcemap --external none --no-pkg-main"
},
"devDependencies": {
"core-js": "3.6.5",
"microbundle": "0.11.0",
"microbundle": "0.13.0",
"object-assign": "4.1.1",
"whatwg-fetch": "3.0.0"
}
Expand Down
15 changes: 10 additions & 5 deletions packages/next/build/babel/plugins/jsx-pragma.ts
Expand Up @@ -55,7 +55,8 @@ export default function ({

// if the React binding came from a require('react'),
// make sure that our usage comes after it.
let newPath
let newPath: NodePath<BabelTypes.VariableDeclaration>

if (
existingBinding &&
t.isVariableDeclarator(existingBinding.path.node) &&
Expand All @@ -67,12 +68,14 @@ export default function ({
mapping
)
} else {
// @ts-ignore
;[newPath] = path.unshiftContainer('body', mapping)
}

for (const declar of newPath.get('declarations')) {
path.scope.registerBinding(newPath.node.kind, declar)
path.scope.registerBinding(
newPath.node.kind,
declar as NodePath<BabelTypes.Node>
)
}
}

Expand All @@ -93,10 +96,12 @@ export default function ({
t.stringLiteral(state.opts.module || 'react')
)

// @ts-ignore
const [newPath] = path.unshiftContainer('body', importSpecifier)
for (const specifier of newPath.get('specifiers')) {
path.scope.registerBinding('module', specifier)
path.scope.registerBinding(
'module',
specifier as NodePath<BabelTypes.Node>
)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/next/build/babel/plugins/next-page-config.ts
@@ -1,7 +1,9 @@
import {
NodePath,
PluginObj,
PluginPass,
types as BabelTypes,
Visitor,
} from 'next/dist/compiled/babel/core'
import { PageConfig } from 'next/types'
import { STRING_LITERAL_DROP_BUNDLE } from '../../../next-server/lib/constants'
Expand Down Expand Up @@ -31,7 +33,7 @@ function errorMessage(state: any, details: string): string {
return `Invalid page config export found. ${details} in file ${pageName}. See: https://err.sh/vercel/next.js/invalid-page-config`
}

interface ConfigState {
interface ConfigState extends PluginPass {
bundleDropped?: boolean
}

Expand All @@ -44,7 +46,7 @@ export default function nextPageConfig({
return {
visitor: {
Program: {
enter(path, state: ConfigState) {
enter(path, state) {
path.traverse(
{
ExportDeclaration(exportPath, exportState) {
Expand Down Expand Up @@ -203,6 +205,6 @@ export default function nextPageConfig({
)
},
},
},
} as Visitor<ConfigState>,
}
}
62 changes: 30 additions & 32 deletions packages/next/build/babel/plugins/next-ssg-transform.ts
Expand Up @@ -42,16 +42,15 @@ function decorateSsgExport(
const gsspId = t.identifier(gsspName)

const addGsspExport = (
exportPath: NodePath<
BabelTypes.ExportDefaultDeclaration | BabelTypes.ExportNamedDeclaration
>
exportPath:
| NodePath<BabelTypes.ExportDefaultDeclaration>
| NodePath<BabelTypes.ExportNamedDeclaration>
): void => {
if (state.done) {
return
}
state.done = true

// @ts-ignore invalid return type
const [pageCompPath] = exportPath.replaceWithMultiple([
t.exportNamedDeclaration(
t.variableDeclaration(
Expand All @@ -65,7 +64,9 @@ function decorateSsgExport(
),
exportPath.node,
])
exportPath.scope.registerDeclaration(pageCompPath)
exportPath.scope.registerDeclaration(
pageCompPath as NodePath<BabelTypes.Node>
)
}

path.traverse({
Expand Down Expand Up @@ -102,11 +103,10 @@ export default function nextTransformSsg({
types: typeof BabelTypes
}): PluginObj<PluginState> {
function getIdentifier(
path: NodePath<
| BabelTypes.FunctionDeclaration
| BabelTypes.FunctionExpression
| BabelTypes.ArrowFunctionExpression
>
path:
| NodePath<BabelTypes.FunctionDeclaration>
| NodePath<BabelTypes.FunctionExpression>
| NodePath<BabelTypes.ArrowFunctionExpression>
): NodePath<BabelTypes.Identifier> | null {
const parentPath = path.parentPath
if (parentPath.type === 'VariableDeclarator') {
Expand Down Expand Up @@ -154,11 +154,10 @@ export default function nextTransformSsg({
}

function markFunction(
path: NodePath<
| BabelTypes.FunctionDeclaration
| BabelTypes.FunctionExpression
| BabelTypes.ArrowFunctionExpression
>,
path:
| NodePath<BabelTypes.FunctionDeclaration>
| NodePath<BabelTypes.FunctionExpression>
| NodePath<BabelTypes.ArrowFunctionExpression>,
state: PluginState
): void {
const ident = getIdentifier(path)
Expand All @@ -168,14 +167,13 @@ export default function nextTransformSsg({
}

function markImport(
path: NodePath<
| BabelTypes.ImportSpecifier
| BabelTypes.ImportDefaultSpecifier
| BabelTypes.ImportNamespaceSpecifier
>,
path:
| NodePath<BabelTypes.ImportSpecifier>
| NodePath<BabelTypes.ImportDefaultSpecifier>
| NodePath<BabelTypes.ImportNamespaceSpecifier>,
state: PluginState
): void {
const local = path.get('local')
const local = path.get('local') as NodePath<BabelTypes.Identifier>
if (isIdentifierReferenced(local)) {
state.refs.add(local)
}
Expand Down Expand Up @@ -320,11 +318,10 @@ export default function nextTransformSsg({
let count: number

function sweepFunction(
sweepPath: NodePath<
| BabelTypes.FunctionDeclaration
| BabelTypes.FunctionExpression
| BabelTypes.ArrowFunctionExpression
>
sweepPath:
| NodePath<BabelTypes.FunctionDeclaration>
| NodePath<BabelTypes.FunctionExpression>
| NodePath<BabelTypes.ArrowFunctionExpression>
): void {
const ident = getIdentifier(sweepPath)
if (
Expand All @@ -346,13 +343,14 @@ export default function nextTransformSsg({
}

function sweepImport(
sweepPath: NodePath<
| BabelTypes.ImportSpecifier
| BabelTypes.ImportDefaultSpecifier
| BabelTypes.ImportNamespaceSpecifier
>
sweepPath:
| NodePath<BabelTypes.ImportSpecifier>
| NodePath<BabelTypes.ImportDefaultSpecifier>
| NodePath<BabelTypes.ImportNamespaceSpecifier>
): void {
const local = sweepPath.get('local')
const local = sweepPath.get('local') as NodePath<
BabelTypes.Identifier
>
if (refs.has(local) && !isIdentifierReferenced(local)) {
++count
sweepPath.remove()
Expand Down
17 changes: 11 additions & 6 deletions packages/next/build/babel/plugins/react-loadable-plugin.ts
Expand Up @@ -71,9 +71,13 @@ export default function ({

if (!callExpression.isCallExpression()) return

let args = callExpression.get('arguments')
const callExpression_ = callExpression as NodePath<
BabelTypes.CallExpression
>

let args = callExpression_.get('arguments')
if (args.length > 2) {
throw callExpression.buildCodeFrameError(
throw callExpression_.buildCodeFrameError(
'next/dynamic only accepts 2 arguments'
)
}
Expand All @@ -89,22 +93,23 @@ export default function ({
options = args[0]
} else {
if (!args[1]) {
callExpression.node.arguments.push(t.objectExpression([]))
callExpression_.node.arguments.push(t.objectExpression([]))
}
// This is needed as the code is modified above
args = callExpression.get('arguments')
args = callExpression_.get('arguments')
loader = args[0]
options = args[1]
}

if (!options.isObjectExpression()) return
const options_ = options as NodePath<BabelTypes.ObjectExpression>

let properties = options.get('properties')
let properties = options_.get('properties')
let propertiesMap: {
[key: string]: NodePath<
| BabelTypes.ObjectProperty
| BabelTypes.ObjectMethod
| BabelTypes.SpreadProperty
| BabelTypes.SpreadElement
>
} = {}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Expand Up @@ -6,7 +6,7 @@ import Worker from 'jest-worker'
import devalue from 'next/dist/compiled/devalue'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import findUp from 'next/dist/compiled/find-up'
import nanoid from 'next/dist/compiled/nanoid/index.js'
import { nanoid } from 'next/dist/compiled/nanoid/index.cjs'
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp'
import path from 'path'
import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages'
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack/loaders/next-babel-loader.js
Expand Up @@ -3,9 +3,9 @@ import hash from 'next/dist/compiled/string-hash'
import { basename, join } from 'path'
import * as Log from '../../output/log'

// increment 'n' to invalidate cache
// increment 'o' to invalidate cache
// eslint-disable-next-line no-useless-concat
const cacheKey = 'babel-cache-' + 'n' + '-'
const cacheKey = 'babel-cache-' + 'o' + '-'
const nextBabelPreset = require('../../babel/preset')

module.exports = babelLoader.custom((babel) => {
Expand Down
Expand Up @@ -337,7 +337,8 @@ class TerserPlugin {
})

const handleHashForChunk = (hash, chunk) => {
hash.update('a')
// increment 'b' to invalidate cache
hash.update('b')
}

if (isWebpack5) {
Expand Down
18 changes: 10 additions & 8 deletions packages/next/compiled/babel/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/compiled/conf/index.js

Large diffs are not rendered by default.