mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 17:27:54 -05:00
Merge pull request #15330 from gcnew/exportConsts
Allow exporting const variables when `strictNullChecks` is on
This commit is contained in:
@@ -11807,7 +11807,7 @@ namespace ts {
|
||||
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
|
||||
// declaration container are the same).
|
||||
const assumeInitialized = isParameter || isOuterVariable ||
|
||||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isInTypeQuery(node)) ||
|
||||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isInTypeQuery(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
|
||||
isInAmbientContext(declaration);
|
||||
const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) :
|
||||
type === autoType || type === autoArrayType ? undefinedType :
|
||||
|
||||
27
tests/baselines/reference/exportBinding.errors.txt
Normal file
27
tests/baselines/reference/exportBinding.errors.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
tests/cases/conformance/es6/modules/exportConsts.ts(3,16): error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
tests/cases/conformance/es6/modules/exportConsts.ts(3,16): error TS2454: Variable 'x' is used before being assigned.
|
||||
tests/cases/conformance/es6/modules/exportVars.ts(3,16): error TS2454: Variable 'y' is used before being assigned.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/modules/exportConsts.ts (2 errors) ====
|
||||
export { x }
|
||||
export { x as xx }
|
||||
export default x;
|
||||
~
|
||||
!!! error TS2448: Block-scoped variable 'x' used before its declaration.
|
||||
~
|
||||
!!! error TS2454: Variable 'x' is used before being assigned.
|
||||
|
||||
const x = 'x'
|
||||
|
||||
export { Y as Z }
|
||||
class Y {}
|
||||
|
||||
==== tests/cases/conformance/es6/modules/exportVars.ts (1 errors) ====
|
||||
export { y }
|
||||
export { y as yy }
|
||||
export default y;
|
||||
~
|
||||
!!! error TS2454: Variable 'y' is used before being assigned.
|
||||
var y = 'y'
|
||||
|
||||
@@ -1,19 +1,39 @@
|
||||
//// [exportBinding.ts]
|
||||
//// [tests/cases/conformance/es6/modules/exportBinding.ts] ////
|
||||
|
||||
//// [exportConsts.ts]
|
||||
export { x }
|
||||
export { x as xx }
|
||||
export default x;
|
||||
|
||||
const x = 'x'
|
||||
|
||||
export { Y as Z }
|
||||
class Y {}
|
||||
|
||||
//// [exportVars.ts]
|
||||
export { y }
|
||||
export { y as yy }
|
||||
export default y;
|
||||
var y = 'y'
|
||||
|
||||
//// [exportBinding.js]
|
||||
|
||||
//// [exportConsts.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = x;
|
||||
var x = 'x';
|
||||
exports.x = x;
|
||||
exports.xx = x;
|
||||
var Y = (function () {
|
||||
function Y() {
|
||||
}
|
||||
return Y;
|
||||
}());
|
||||
exports.Z = Y;
|
||||
//// [exportVars.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = y;
|
||||
var y = 'y';
|
||||
exports.y = y;
|
||||
exports.yy = y;
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
// @filename: exportConsts.ts
|
||||
// @strict: true
|
||||
export { x }
|
||||
export { x as xx }
|
||||
export default x;
|
||||
|
||||
const x = 'x'
|
||||
|
||||
export { Y as Z }
|
||||
class Y {}
|
||||
|
||||
// @filename: exportVars.ts
|
||||
// @strict: true
|
||||
export { y }
|
||||
export { y as yy }
|
||||
export default y;
|
||||
var y = 'y'
|
||||
|
||||
Reference in New Issue
Block a user