Issue 1:
Bug Report

Current Behavior

A clear and concise description of the behavior.

Input Code

REPL or Repo link if applicable:

TypeError: Cannot read property 'buildError' of undefined
at Scope.checkBlockScopedCollisions (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/scope/index.js:347:22)
at Scope.registerBinding (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/scope/index.js:504:16)
at Scope.registerDeclaration (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/scope/index.js:452:14)
at Object.Declaration (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/scope/index.js:125:12)
at NodePath._call (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitMultiple (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/context.js:85:17)
at TraversalContext.visit (/Users/puss/work/ioc/parrot-tool-must/node_modules/_@babel_traverse@7.0.0@@babel/traverse/lib/context.js:144:19)

Environment

Babel version(s): [v7.0.0]

Node/npm version: [Node v10.9.0/npm 5.15.0]

OS: [e.g. OSX 10.13.6]

Monorepo [e.g. yes/no/Lerna]

How you are using Babel: [AST parser]

.

Issue 2:
Bug Report

Current Behavior

@babel/traverse tries to throw a Duplicate declaration error for key duplicates in different ambient module declarations in one file. @babel/parser with typescript plugin is used to build an AST.

#4640 explains why Cannot read property 'file' of undefined is thrown.

Input Code

const parse = require('@babel/parser').parse;
const traverse = require('@babel/traverse').default;

const code = `
declare module 'module1' {
export const variable: string;
}

declare module 'module2' {
export const variable: number;
}
`;

const ast = parse(code, {
sourceType: 'module',
plugins: ['typescript']
});

traverse(ast, {
enter(path) {
// smth
}
});

Output

...\node_modules\@babel\traverse\lib\scope\index.js:347
throw this.hub.file.buildCodeFrameError(id, `Duplicate declaration "${name}"`, TypeError);
^

TypeError: Cannot read property 'file' of undefined
at Scope.checkBlockScopedCollisions (...\node_modules\@babel\traverse\lib\scope\index.js:347:22)
at Scope.registerBinding (...\node_modules\@babel\traverse\lib\scope\index.js:506:16)
at Scope.registerDeclaration (...\node_modules\@babel\traverse\lib\scope\index.js:454:14)
at Object.Declaration (...\node_modules\@babel\traverse\lib\scope\index.js:125:12)
at NodePath._call (...\node_modules\@babel\traverse\lib\path\context.js:53:20)
at NodePath.call (...\node_modules\@babel\traverse\lib\path\context.js:40:17)
at NodePath.visit (...\node_modules\@babel\traverse\lib\path\context.js:88:12)
at TraversalContext.visitQueue (...\node_modules\@babel\traverse\lib\context.js:118:16)
at TraversalContext.visitMultiple (...\node_modules\@babel\traverse\lib\context.js:85:17)
at TraversalContext.visit (...\node_modules\@babel\traverse\lib\context.js:144:19)

Expected behavior

Each module declaration has its own block scope, so the Duplicate declaration error shouldn't be thrown.

Environment

Babel version: v7.0.0-beta.51

Node/npm version: node 8.11.3 / npm 5.6.0

OS: Windows 10