Issue 1:
Issue originally made by @vadzim

Bug information

Babel version: 6.3.17 (babel-core 6.3.17)

Node version: v5.1.1

npm version: 3.3.12

Options

--no-babelrc --presets es2015

Input code

var x = { method() {
var f = () => console.log( this.method, null && method )
f()
} }
x.method()

Description

Babel generated code fails:

> echo "var x = { method() {
var f = () => console.log( this.method, null && method )
f()
} }
x.method()" | ./node_modules/.bin/babel --no-babelrc --presets es2015 | node
[stdin]:17
return console.log(_this.method, null && method);
^

TypeError: Cannot read property 'method' of undefined
at f ([stdin]:17:37)
at Object.<anonymous> ([stdin]:19:9)
at Object.method ([stdin]:7:28)
at [stdin]:22:3
at Object.exports.runInThisContext (vm.js:54:17)
at Object.<anonymous> ([stdin]-wrapper:6:22)
at Module._compile (module.js:425:26)
at node.js:589:27
at doNTCallback0 (node.js:430:9)
at process._tickCallback (node.js:359:13)
>

while code without compilation works in node pretty well:

> echo "var x = { method() {
var f = () => console.log( this.method, null && method )
f()
} }
x.method()" | node
[Function: method] null
>

The problem is that babel loses this pointer. Generated code is:

"use strict";

var _this = undefined;
var x = {
method: (function (_method) {
function method() {
return _method.apply(this, arguments);
}

method.toString = function () {
return _method.toString();
};

return method;
})(function () {
var f = function f() {
return console.log(_this.method, null && method);
};
f();
})
};
x.method();

The problem appers when method is accessed by its name in its body.

Issue 2:
I'm building an SSR template, and when I use @babebl/register and then execute webpack (config), the system reported an error.

I tried @babel/polyfill and @babel/plugin-transform-runtime, but none of them worked.

Input code

index.js:

require("ignore-styles");
require("@babel/register")({
ignore: [/\/(build|node_modules)\//],
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["@babel/plugin-syntax-dynamic-import", "dynamic-import-node"]
});
require("./server");

server.js

const config = require('../config/webpack.dev.config.js')
const webpack = require('webpack')
const express = require('express')
const webpackDevMiddleware = require('webpack-dev-middleware')
const reactRouter = require('react-router')
const StaticRouter = reactRouter.reactRouter;
const app = express()
const complier = webpack(config)
const PORT = 8090
...
app.use(webpackDevMiddleware(complier, {
publicPath: config.output.publicPath
}))

app.listen(PORT , function() {
console.log(`SSR running on port ${PORT }`);
})

webpack.dev.config.js

const paths = require('./paths')
const webpack = require('webpack')
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
entry: ['webpack-hot-middleware/client?reload=true', paths.appIndexJs],
output: {
path: paths.clientBuild,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: paths.publicPath
},
devtool: 'eval-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: "2",
targets: {
browsers: ['last 2 versions', 'ie >= 9'],
},
}],
'@babel/preset-react'
]
}
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new htmlWebpackPlugin({
template: './client/index.html',
filename: 'index.html'
})
]
}

Error message

Environment

Babel version(s): 7.4.3

Node/npm version: [e.g. Node 10.15.3/npm 6.4.1]

OS: window 10

Rep

https://github.com/xuchenchenBoy/ssr （Please execute npm run dev:server and release notes in server.js）