fix: get rid of CRLF (#5494)

master
Ika 2018-12-08 18:28:29 +08:00 committed by GitHub
parent b878a54e6a
commit 952bc0cc03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
131 changed files with 2071 additions and 2494 deletions

5
.gitattributes vendored
View File

@ -1,4 +1 @@
# Make sure baseline files have consistent line endings * text=auto eol=lf
*.txt text eol=lf
*.snap text eol=lf
*.debug-check text eol=lf

View File

@ -1,6 +1,6 @@
trigger: trigger:
- master - master
- releases-* - release-*
variables: variables:
AST_COMPARE: true AST_COMPARE: true
@ -31,6 +31,7 @@ jobs:
vmImage: vs2017-win2016 vmImage: vs2017-win2016
variables: variables:
node_version: 10 node_version: 10
TEST_CRLF: true
steps: steps:
- template: .azure-pipelines/dev.yml - template: .azure-pipelines/dev.yml

View File

@ -17,13 +17,9 @@ module.exports = {
"jest-snapshot-serializer-ansi" "jest-snapshot-serializer-ansi"
], ],
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
testPathIgnorePatterns: ["tests/new_react", "tests/more_react"] testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat(
.concat(isOldNode ? requiresPrettierInternals : []) isOldNode ? requiresPrettierInternals : []
.concat( ),
require("os").EOL == "\n"
? ["tests_integration/__tests__/eol-crlf.js"]
: ["tests_integration/__tests__/eol-lf.js"]
),
collectCoverage: ENABLE_COVERAGE, collectCoverage: ENABLE_COVERAGE,
collectCoverageFrom: ["src/**/*.js", "index.js", "!<rootDir>/node_modules/"], collectCoverageFrom: ["src/**/*.js", "index.js", "!<rootDir>/node_modules/"],
coveragePathIgnorePatterns: [ coveragePathIgnorePatterns: [

View File

@ -71,8 +71,8 @@
"unicode-regex": "2.0.0", "unicode-regex": "2.0.0",
"unified": "6.1.6", "unified": "6.1.6",
"vnopts": "1.0.2", "vnopts": "1.0.2",
"yaml": "1.0.0-rc.8", "yaml": "1.0.2",
"yaml-unist-parser": "1.0.0-rc.4" "yaml-unist-parser": "1.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.1.5", "@babel/cli": "7.1.5",

View File

@ -675,7 +675,19 @@ function isWithinParentArrayProperty(path, propertyName) {
return parent[propertyName][key] === node; return parent[propertyName][key] === node;
} }
function replaceEndOfLineWith(text, replacement) {
const parts = [];
for (const part of text.split("\n")) {
if (parts.length !== 0) {
parts.push(replacement);
}
parts.push(part);
}
return parts;
}
module.exports = { module.exports = {
replaceEndOfLineWith,
getStringWidth, getStringWidth,
getMaxContinuousCount, getMaxContinuousCount,
getPrecedence, getPrecedence,

View File

@ -110,11 +110,7 @@ function genericPrint(path, options, print) {
} }
case "css-comment": { case "css-comment": {
if (node.raws.content) { if (node.raws.content) {
return ( return node.raws.content;
node.raws.content
// there's a bug in the less parser that trailing `\r`s are included in inline comments
.replace(/^(\/\/[^]+)\r+$/, "$1")
);
} }
const text = options.originalText.slice( const text = options.originalText.slice(
options.locStart(node), options.locStart(node),

View File

@ -265,7 +265,6 @@ function createParser({
allowHtmComponentClosingTags = false allowHtmComponentClosingTags = false
} = {}) { } = {}) {
return { return {
preprocess: text => text.replace(/\r\n?/g, "\n"),
parse: (text, parsers, options) => parse: (text, parsers, options) =>
_parse(text, options, { _parse(text, options, {
recognizeSelfClosing, recognizeSelfClosing,

View File

@ -34,12 +34,11 @@ const {
isTextLikeNode, isTextLikeNode,
normalizeParts, normalizeParts,
preferHardlineAsLeadingSpaces, preferHardlineAsLeadingSpaces,
replaceDocNewlines,
replaceNewlines,
shouldNotPrintClosingTag, shouldNotPrintClosingTag,
shouldPreserveContent, shouldPreserveContent,
unescapeQuoteEntities unescapeQuoteEntities
} = require("./utils"); } = require("./utils");
const { replaceEndOfLineWith } = require("../common/util");
const preprocess = require("./preprocess"); const preprocess = require("./preprocess");
const assert = require("assert"); const assert = require("assert");
const { insertPragma } = require("./pragma"); const { insertPragma } = require("./pragma");
@ -147,10 +146,7 @@ function embed(path, print, textToDoc, options) {
hardline, hardline,
node.value.trim().length === 0 node.value.trim().length === 0
? "" ? ""
: replaceDocNewlines( : textToDoc(node.value, { parser: "yaml" }),
textToDoc(node.value, { parser: "yaml" }),
literalline
),
"---" "---"
]) ])
); );
@ -287,7 +283,7 @@ function genericPrint(path, options, print) {
? node.value.replace(trailingNewlineRegex, "") ? node.value.replace(trailingNewlineRegex, "")
: node.value; : node.value;
return concat([ return concat([
concat(replaceNewlines(value, literalline)), concat(replaceEndOfLineWith(value, literalline)),
hasTrailingNewline ? hardline : "" hasTrailingNewline ? hardline : ""
]); ]);
} }
@ -316,7 +312,7 @@ function genericPrint(path, options, print) {
return concat([ return concat([
printOpeningTagPrefix(node, options), printOpeningTagPrefix(node, options),
concat( concat(
replaceNewlines( replaceEndOfLineWith(
options.originalText.slice( options.originalText.slice(
options.locStart(node), options.locStart(node),
options.locEnd(node) options.locEnd(node)
@ -341,7 +337,7 @@ function genericPrint(path, options, print) {
"=", "=",
quote, quote,
concat( concat(
replaceNewlines( replaceEndOfLineWith(
quote === '"' quote === '"'
? value.replace(/"/g, "&quot;") ? value.replace(/"/g, "&quot;")
: value.replace(/'/g, "&apos;"), : value.replace(/'/g, "&apos;"),
@ -354,7 +350,7 @@ function genericPrint(path, options, print) {
} }
case "yaml": case "yaml":
case "toml": case "toml":
return node.raw; return concat(replaceEndOfLineWith(node.raw, literalline));
default: default:
throw new Error(`Unexpected node type ${node.type}`); throw new Error(`Unexpected node type ${node.type}`);
} }
@ -473,7 +469,7 @@ function printChildren(path, options, print) {
return concat( return concat(
[].concat( [].concat(
printOpeningTagPrefix(child, options), printOpeningTagPrefix(child, options),
replaceNewlines( replaceEndOfLineWith(
options.originalText.slice( options.originalText.slice(
options.locStart(child) + options.locStart(child) +
(child.prev && (child.prev &&
@ -497,7 +493,7 @@ function printChildren(path, options, print) {
[].concat( [].concat(
printOpeningTagPrefix(child, options), printOpeningTagPrefix(child, options),
group(printOpeningTag(childPath, options, print)), group(printOpeningTag(childPath, options, print)),
replaceNewlines( replaceEndOfLineWith(
options.originalText.slice( options.originalText.slice(
child.startSourceSpan.end.offset + child.startSourceSpan.end.offset +
(child.firstChild && (child.firstChild &&
@ -620,7 +616,7 @@ function printOpeningTag(path, options, print) {
const attr = attrPath.getValue(); const attr = attrPath.getValue();
return hasPrettierIgnoreAttribute(attr) return hasPrettierIgnoreAttribute(attr)
? concat( ? concat(
replaceNewlines( replaceEndOfLineWith(
options.originalText.slice( options.originalText.slice(
options.locStart(attr), options.locStart(attr),
options.locEnd(attr) options.locEnd(attr)
@ -894,8 +890,8 @@ function printClosingTagEndMarker(node, options) {
function getTextValueParts(node, value = node.value) { function getTextValueParts(node, value = node.value) {
return node.parent.isWhitespaceSensitive return node.parent.isWhitespaceSensitive
? node.parent.isIndentationSensitive ? node.parent.isIndentationSensitive
? replaceNewlines(value, literalline) ? replaceEndOfLineWith(value, literalline)
: replaceNewlines( : replaceEndOfLineWith(
dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")), dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")),
hardline hardline
) )
@ -1037,7 +1033,7 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
const parts = []; const parts = [];
value.split(interpolationRegex).forEach((part, index) => { value.split(interpolationRegex).forEach((part, index) => {
if (index % 2 === 0) { if (index % 2 === 0) {
parts.push(concat(replaceNewlines(part, literalline))); parts.push(concat(replaceEndOfLineWith(part, literalline)));
} else { } else {
try { try {
parts.push( parts.push(
@ -1056,7 +1052,11 @@ function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
) )
); );
} catch (e) { } catch (e) {
parts.push("{{", concat(replaceNewlines(part, literalline)), "}}"); parts.push(
"{{",
concat(replaceEndOfLineWith(part, literalline)),
"}}"
);
} }
} }
}); });

View File

@ -1,10 +1,5 @@
"use strict"; "use strict";
const {
builders: { concat },
utils: { mapDoc }
} = require("../doc");
const { const {
CSS_DISPLAY_TAGS, CSS_DISPLAY_TAGS,
CSS_DISPLAY_DEFAULT, CSS_DISPLAY_DEFAULT,
@ -263,20 +258,6 @@ function isDanglingSpaceSensitiveNode(node) {
); );
} }
function replaceNewlines(text, replacement) {
return text
.split(/(\n)/g)
.map((data, index) => (index % 2 === 1 ? replacement : data));
}
function replaceDocNewlines(doc, replacement) {
return mapDoc(doc, currentDoc =>
typeof currentDoc === "string" && currentDoc.includes("\n")
? concat(replaceNewlines(currentDoc, replacement))
: currentDoc
);
}
function forceNextEmptyLine(node) { function forceNextEmptyLine(node) {
return ( return (
isFrontMatterNode(node) || isFrontMatterNode(node) ||
@ -645,8 +626,6 @@ module.exports = {
normalizeParts, normalizeParts,
preferHardlineAsLeadingSpaces, preferHardlineAsLeadingSpaces,
preferHardlineAsTrailingSpaces, preferHardlineAsTrailingSpaces,
replaceDocNewlines,
replaceNewlines,
shouldNotPrintClosingTag, shouldNotPrintClosingTag,
shouldPreserveContent, shouldPreserveContent,
unescapeQuoteEntities unescapeQuoteEntities

View File

@ -2395,7 +2395,10 @@ function printPathNoParens(path, options, print, args) {
"${" + "${" +
printDocToString( printDocToString(
doc, doc,
Object.assign({}, options, { printWidth: Infinity }) Object.assign({}, options, {
printWidth: Infinity,
endOfLine: "lf"
})
).formatted + ).formatted +
"}" "}"
); );

View File

@ -42,7 +42,7 @@ function embed(path, print, textToDoc, options) {
concat([ concat([
"---", "---",
hardline, hardline,
node.value.trim() node.value && node.value.trim()
? replaceNewlinesWithLiterallines( ? replaceNewlinesWithLiterallines(
textToDoc(node.value, { parser: "yaml" }) textToDoc(node.value, { parser: "yaml" })
) )

View File

@ -9,7 +9,7 @@ function startWithPragma(text) {
const regex = new RegExp( const regex = new RegExp(
[ [
`<!--\\s*${pragma}\\s*-->`, `<!--\\s*${pragma}\\s*-->`,
`<!--.*\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->` `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`
].join("|"), ].join("|"),
"m" "m"
); );

View File

@ -27,6 +27,7 @@ const {
splitText, splitText,
punctuationPattern punctuationPattern
} = require("./utils"); } = require("./utils");
const { replaceEndOfLineWith } = require("../common/util");
const TRAILING_HARDLINE_NODES = ["importExport"]; const TRAILING_HARDLINE_NODES = ["importExport"];
@ -209,7 +210,10 @@ function genericPrint(path, options, print) {
const alignment = " ".repeat(4); const alignment = " ".repeat(4);
return align( return align(
alignment, alignment,
concat([alignment, replaceNewlinesWith(node.value, hardline)]) concat([
alignment,
concat(replaceEndOfLineWith(node.value, hardline))
])
); );
} }
@ -225,9 +229,11 @@ function genericPrint(path, options, print) {
style, style,
node.lang || "", node.lang || "",
hardline, hardline,
replaceNewlinesWith( concat(
getFencedCodeBlockValue(node, options.originalText), replaceEndOfLineWith(
hardline getFencedCodeBlockValue(node, options.originalText),
hardline
)
), ),
hardline, hardline,
style style
@ -247,9 +253,11 @@ function genericPrint(path, options, print) {
? node.value.trimRight() ? node.value.trimRight()
: node.value; : node.value;
const isHtmlComment = /^<!--[\s\S]*-->$/.test(value); const isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
return replaceNewlinesWith( return concat(
value, replaceEndOfLineWith(
isHtmlComment ? hardline : markAsRoot(literalline) value,
isHtmlComment ? hardline : markAsRoot(literalline)
)
); );
} }
case "list": { case "list": {
@ -394,7 +402,7 @@ function genericPrint(path, options, print) {
? concat([" ", markAsRoot(literalline)]) ? concat([" ", markAsRoot(literalline)])
: concat(["\\", hardline]); : concat(["\\", hardline]);
case "liquidNode": case "liquidNode":
return replaceNewlinesWith(node.value, hardline); return concat(replaceEndOfLineWith(node.value, hardline));
// MDX // MDX
case "importExport": case "importExport":
case "jsx": case "jsx":
@ -404,7 +412,10 @@ function genericPrint(path, options, print) {
"$$", "$$",
hardline, hardline,
node.value node.value
? concat([replaceNewlinesWith(node.value, hardline), hardline]) ? concat([
concat(replaceEndOfLineWith(node.value, hardline)),
hardline
])
: "", : "",
"$$" "$$"
]); ]);
@ -467,10 +478,6 @@ function getNthListSiblingIndex(node, parentNode) {
); );
} }
function replaceNewlinesWith(str, doc) {
return join(doc, str.replace(/\r\n?/g, "\n").split("\n"));
}
function getNthSiblingIndex(node, parentNode, condition) { function getNthSiblingIndex(node, parentNode, condition) {
condition = condition || (() => true); condition = condition || (() => true);

View File

@ -148,7 +148,7 @@ function getFencedCodeBlockValue(node, originalText) {
const leadingSpaceCount = text.match(/^\s*/)[0].length; const leadingSpaceCount = text.match(/^\s*/)[0].length;
const replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`); const replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
const lineContents = text.replace(/\r\n?/g, "\n").split("\n"); const lineContents = text.split("\n");
const markerStyle = text[leadingSpaceCount]; // ` or ~ const markerStyle = text[leadingSpaceCount]; // ` or ~
const marker = text const marker = text

View File

@ -29,11 +29,7 @@ const parser = {
parse, parse,
hasPragma, hasPragma,
locStart: node => node.position.start.offset, locStart: node => node.position.start.offset,
locEnd: node => node.position.end.offset, locEnd: node => node.position.end.offset
// workaround for https://github.com/eemeli/yaml/issues/20
preprocess: text =>
text.indexOf("\r") === -1 ? text : text.replace(/\r\n?/g, "\n")
}; };
module.exports = { module.exports = {

View File

@ -38,6 +38,7 @@ const {
markAsRoot, markAsRoot,
softline softline
} = docBuilders; } = docBuilders;
const { replaceEndOfLineWith } = require("../common/util");
function preprocess(ast) { function preprocess(ast) {
return mapNode(ast, defineShortcuts); return mapNode(ast, defineShortcuts);
@ -104,9 +105,14 @@ function genericPrint(path, options, print) {
]) ])
: "", : "",
hasPrettierIgnore(path) hasPrettierIgnore(path)
? options.originalText.slice( ? concat(
node.position.start.offset, replaceEndOfLineWith(
node.position.end.offset options.originalText.slice(
node.position.start.offset,
node.position.end.offset
),
literalline
)
) )
: group(_print(node, parentNode, path, options, print)), : group(_print(node, parentNode, path, options, print)),
hasTrailingComment(node) && !isNode(node, ["document", "documentHead"]) hasTrailingComment(node) && !isNode(node, ["document", "documentHead"])

View File

@ -1,8 +1,6 @@
"use strict"; "use strict";
function getLast(array) { const { getLast } = require("../common/util");
return array[array.length - 1];
}
function getAncestorCount(path, filter) { function getAncestorCount(path, filter) {
let counter = 0; let counter = 0;

View File

@ -14,6 +14,7 @@ const {
const rangeUtil = require("./range-util"); const rangeUtil = require("./range-util");
const privateUtil = require("../common/util"); const privateUtil = require("../common/util");
const { const {
utils: { mapDoc },
printer: { printDocToString }, printer: { printDocToString },
debug: { printDocToDebug } debug: { printDocToDebug }
} = require("../doc"); } = require("../doc");
@ -21,6 +22,11 @@ const {
const UTF8BOM = 0xfeff; const UTF8BOM = 0xfeff;
const CURSOR = Symbol("cursor"); const CURSOR = Symbol("cursor");
const PLACEHOLDERS = {
cursorOffset: "<<<PRETTIER_CURSOR>>>",
rangeStart: "<<<PRETTIER_RANGE_START>>>",
rangeEnd: "<<<PRETTIER_RANGE_END>>>"
};
function ensureAllCommentsPrinted(astComments) { function ensureAllCommentsPrinted(astComments) {
if (!astComments) { if (!astComments) {
@ -67,8 +73,6 @@ function coreFormat(text, opts, addAlignmentSize) {
const parsed = parser.parse(text, opts); const parsed = parser.parse(text, opts);
const ast = parsed.ast; const ast = parsed.ast;
const originalText = text;
text = parsed.text; text = parsed.text;
if (opts.cursorOffset >= 0) { if (opts.cursorOffset >= 0) {
@ -80,11 +84,18 @@ function coreFormat(text, opts, addAlignmentSize) {
const astComments = attachComments(text, ast, opts); const astComments = attachComments(text, ast, opts);
const doc = printAstToDoc(ast, opts, addAlignmentSize); const doc = printAstToDoc(ast, opts, addAlignmentSize);
if (opts.endOfLine === "auto") {
opts.endOfLine = guessEndOfLine(originalText);
}
const result = printDocToString(doc, opts); const eol = convertEndOfLineToChars(opts.endOfLine);
const result = printDocToString(
opts.endOfLine === "lf"
? doc
: mapDoc(doc, currentDoc =>
typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1
? currentDoc.replace(/\n/g, eol)
: currentDoc
),
opts
);
ensureAllCommentsPrinted(astComments); ensureAllCommentsPrinted(astComments);
// Remove extra leading indentation as well as the added indentation after last newline // Remove extra leading indentation as well as the added indentation after last newline
@ -212,8 +223,8 @@ function formatRange(text, opts) {
// Since the range contracts to avoid trailing whitespace, // Since the range contracts to avoid trailing whitespace,
// we need to remove the newline that was inserted by the `format` call. // we need to remove the newline that was inserted by the `format` call.
const rangeTrimmed = rangeResult.formatted.trimRight(); const rangeTrimmed = rangeResult.formatted.trimRight();
const formatted = const rangeLeft = text.slice(0, rangeStart);
text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd); const rangeRight = text.slice(rangeEnd);
let cursorOffset = opts.cursorOffset; let cursorOffset = opts.cursorOffset;
if (opts.cursorOffset >= rangeEnd) { if (opts.cursorOffset >= rangeEnd) {
@ -226,6 +237,44 @@ function formatRange(text, opts) {
} }
// keep the cursor as it was if it was before the start of the range // keep the cursor as it was if it was before the start of the range
let formatted;
if (opts.endOfLine === "lf") {
formatted = rangeLeft + rangeTrimmed + rangeRight;
} else {
const eol = convertEndOfLineToChars(opts.endOfLine);
if (cursorOffset >= 0) {
const parts = [rangeLeft, rangeTrimmed, rangeRight];
let partIndex = 0;
let partOffset = cursorOffset;
while (partIndex < parts.length) {
const part = parts[partIndex];
if (partOffset < part.length) {
parts[partIndex] =
parts[partIndex].slice(0, partOffset) +
PLACEHOLDERS.cursorOffset +
parts[partIndex].slice(partOffset);
break;
}
partIndex++;
partOffset -= part.length;
}
const [newRangeLeft, newRangeTrimmed, newRangeRight] = parts;
formatted = (
newRangeLeft.replace(/\n/g, eol) +
newRangeTrimmed +
newRangeRight.replace(/\n/g, eol)
).replace(PLACEHOLDERS.cursorOffset, (_, index) => {
cursorOffset = index;
return "";
});
} else {
formatted =
rangeLeft.replace(/\n/g, eol) +
rangeTrimmed +
rangeRight.replace(/\n/g, eol);
}
}
return { formatted, cursorOffset }; return { formatted, cursorOffset };
} }
@ -236,23 +285,83 @@ function format(text, opts) {
return { formatted: text }; return { formatted: text };
} }
if (opts.rangeStart > 0 || opts.rangeEnd < text.length) { if (opts.endOfLine === "auto") {
return formatRange(text, opts); opts.endOfLine = guessEndOfLine(text);
}
const hasCursor = opts.cursorOffset >= 0;
const hasRangeStart = opts.rangeStart > 0;
const hasRangeEnd = opts.rangeEnd < text.length;
// get rid of CR/CRLF parsing
if (text.indexOf("\r") !== -1) {
const offsetKeys = [
hasCursor && "cursorOffset",
hasRangeStart && "rangeStart",
hasRangeEnd && "rangeEnd"
]
.filter(Boolean)
.sort((aKey, bKey) => opts[aKey] - opts[bKey]);
for (let i = offsetKeys.length - 1; i >= 0; i--) {
const key = offsetKeys[i];
text =
text.slice(0, opts[key]) + PLACEHOLDERS[key] + text.slice(opts[key]);
}
text = text.replace(/\r\n?/g, "\n");
for (let i = 0; i < offsetKeys.length; i++) {
const key = offsetKeys[i];
text = text.replace(PLACEHOLDERS[key], (_, index) => {
opts[key] = index;
return "";
});
}
} }
const hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM; const hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
if (hasUnicodeBOM) { if (hasUnicodeBOM) {
text = text.substring(1); text = text.substring(1);
if (hasCursor) {
opts.cursorOffset++;
}
if (hasRangeStart) {
opts.rangeStart++;
}
if (hasRangeEnd) {
opts.rangeEnd++;
}
} }
if (opts.insertPragma && opts.printer.insertPragma && !hasPragma) { if (!hasCursor) {
text = opts.printer.insertPragma(text); opts.cursorOffset = -1;
}
if (opts.rangeStart < 0) {
opts.rangeStart = 0;
}
if (opts.rangeEnd > text.length) {
opts.rangeEnd = text.length;
} }
const result = coreFormat(text, opts); const result =
hasRangeStart || hasRangeEnd
? formatRange(text, opts)
: coreFormat(
opts.insertPragma && opts.printer.insertPragma && !hasPragma
? opts.printer.insertPragma(text)
: text,
opts
);
if (hasUnicodeBOM) { if (hasUnicodeBOM) {
result.formatted = String.fromCharCode(UTF8BOM) + result.formatted; result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
if (hasCursor) {
result.cursorOffset++;
}
} }
return result; return result;
} }
@ -264,6 +373,9 @@ module.exports = {
parse(text, opts, massage) { parse(text, opts, massage) {
opts = normalizeOptions(opts); opts = normalizeOptions(opts);
if (text.indexOf("\r") !== -1) {
text = text.replace(/\r\n?/g, "\n");
}
const parsed = parser.parse(text, opts); const parsed = parser.parse(text, opts);
if (massage) { if (massage) {
parsed.ast = massageAST(parsed.ast, opts); parsed.ast = massageAST(parsed.ast, opts);

View File

@ -1,28 +1,28 @@
<div <div
// comment // comment
> >
{foo} {foo}
</div>; </div>;
<div <div
// comment // comment
attr="foo" attr="foo"
> >
{foo} {foo}
</div>; </div>;
<div <div
attr="foo" // comment attr="foo" // comment
> >
{foo} {foo}
</div>; </div>;
<div <div
attr="foo" attr="foo"
// comment // comment
> >
{foo} {foo}
</div>; </div>;
<br // comment <br // comment
/>; />;

View File

@ -1,36 +1,36 @@
import {observable} from "mobx"; import {observable} from "mobx";
@observer class OrderLine { @observer class OrderLine {
@observable price:number = 0; @observable price:number = 0;
@observable amount:number = 1; @observable amount:number = 1;
constructor(price) { constructor(price) {
this.price = price; this.price = price;
} }
@computed get total() { @computed get total() {
return this.price * this.amount; return this.price * this.amount;
} }
@action.bound setPrice(price) { @action.bound setPrice(price) {
this.price = price; this.price = price;
} }
@computed @computed
get total() { get total() {
return this.price * this.amount; return this.price * this.amount;
} }
@action.bound @action.bound
setPrice(price) { setPrice(price) {
this.price = price; this.price = price;
} }
@computed @computed @computed @computed @computed @computed @computed get total() { @computed @computed @computed @computed @computed @computed @computed get total() {
return this.price * this.amount; return this.price * this.amount;
} }
@action handleDecrease = (event: React.ChangeEvent<HTMLInputElement>) => this.count--; @action handleDecrease = (event: React.ChangeEvent<HTMLInputElement>) => this.count--;
@action handleSomething = (event: React.ChangeEvent<HTMLInputElement>) => doSomething(); @action handleSomething = (event: React.ChangeEvent<HTMLInputElement>) => doSomething();
} }

View File

@ -29,7 +29,7 @@
'meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61' 'meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61'
'escaped newline \ 'escaped newline \
' '
'escaped carriage return \ 'escaped carriage return \
' '
'escaped \u2028 \' 'escaped \u2028 \'
'escaped \u2029 \' 'escaped \u2029 \'

View File

@ -1,145 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`usingCrlf.js 1`] = ` exports[`example.js 1`] = `
====================================options=====================================
parsers: ["babylon"]
printWidth: 80
| printWidth
=====================================input======================================
function f() {
console.log("testing line endings");
}
=====================================output=====================================
function f() {
console.log("testing line endings");
}
================================================================================
`;
exports[`usingCrlf.js 2`] = `
====================================options===================================== ====================================options=====================================
endOfLine: "cr" endOfLine: "cr"
parsers: ["babylon"] parsers: ["babylon"]
printWidth: 80 printWidth: 80
| printWidth | printWidth
=====================================input====================================== =====================================input======================================
function f() { function f() {<LF>
console.log("testing line endings"); console.log("testing line endings");<LF>
} }<LF>
=====================================output===================================== =====================================output=====================================
function f() {/*CR*/ console.log("testing line endings");/*CR*/}/*CR*/ function f() {<CR>
console.log("testing line endings");<CR>
}<CR>
================================================================================ ================================================================================
`; `;
exports[`usingCrlf.js 3`] = ` exports[`example.js 2`] = `
====================================options===================================== ====================================options=====================================
endOfLine: "crlf" endOfLine: "crlf"
parsers: ["babylon"] parsers: ["babylon"]
printWidth: 80 printWidth: 80
| printWidth | printWidth
=====================================input====================================== =====================================input======================================
function f() { function f() {<LF>
console.log("testing line endings"); console.log("testing line endings");<LF>
} }<LF>
=====================================output===================================== =====================================output=====================================
function f() {/*CR*/ function f() {<CRLF>
console.log("testing line endings");/*CR*/ console.log("testing line endings");<CRLF>
}/*CR*/ }<CRLF>
================================================================================ ================================================================================
`; `;
exports[`usingCrlf.js 4`] = ` exports[`example.js 3`] = `
====================================options===================================== ====================================options=====================================
endOfLine: "lf" endOfLine: "lf"
parsers: ["babylon"] parsers: ["babylon"]
printWidth: 80 printWidth: 80
| printWidth | printWidth
=====================================input====================================== =====================================input======================================
function f() { function f() {<LF>
console.log("testing line endings"); console.log("testing line endings");<LF>
} }<LF>
=====================================output===================================== =====================================output=====================================
function f() { function f() {<LF>
console.log("testing line endings"); console.log("testing line endings");<LF>
} }<LF>
================================================================================
`;
exports[`usingLf.js 1`] = `
====================================options=====================================
parsers: ["babylon"]
printWidth: 80
| printWidth
=====================================input======================================
function f() {
console.log("testing line endings");
}
=====================================output=====================================
function f() {
console.log("testing line endings");
}
================================================================================
`;
exports[`usingLf.js 2`] = `
====================================options=====================================
endOfLine: "cr"
parsers: ["babylon"]
printWidth: 80
| printWidth
=====================================input======================================
function f() {
console.log("testing line endings");
}
=====================================output=====================================
function f() {/*CR*/ console.log("testing line endings");/*CR*/}/*CR*/
================================================================================
`;
exports[`usingLf.js 3`] = `
====================================options=====================================
endOfLine: "crlf"
parsers: ["babylon"]
printWidth: 80
| printWidth
=====================================input======================================
function f() {
console.log("testing line endings");
}
=====================================output=====================================
function f() {/*CR*/
console.log("testing line endings");/*CR*/
}/*CR*/
================================================================================
`;
exports[`usingLf.js 4`] = `
====================================options=====================================
endOfLine: "lf"
parsers: ["babylon"]
printWidth: 80
| printWidth
=====================================input======================================
function f() {
console.log("testing line endings");
}
=====================================output=====================================
function f() {
console.log("testing line endings");
}
================================================================================ ================================================================================
`; `;

View File

@ -1,4 +1,3 @@
run_spec(__dirname, ["babylon"]);
run_spec(__dirname, ["babylon"], { endOfLine: "cr" }); run_spec(__dirname, ["babylon"], { endOfLine: "cr" });
run_spec(__dirname, ["babylon"], { endOfLine: "crlf" }); run_spec(__dirname, ["babylon"], { endOfLine: "crlf" });
run_spec(__dirname, ["babylon"], { endOfLine: "lf" }); run_spec(__dirname, ["babylon"], { endOfLine: "lf" });

View File

@ -1,3 +0,0 @@
function f() {
console.log("testing line endings");
}

View File

@ -1,137 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`usingCrlf.css 1`] = `
====================================options=====================================
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {
margin: 42px;
}
================================================================================
`;
exports[`usingCrlf.css 2`] = `
====================================options=====================================
endOfLine: "cr"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {/*CR*/ margin: 42px;/*CR*/}/*CR*/
================================================================================
`;
exports[`usingCrlf.css 3`] = `
====================================options=====================================
endOfLine: "crlf"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {/*CR*/
margin: 42px;/*CR*/
}/*CR*/
================================================================================
`;
exports[`usingCrlf.css 4`] = `
====================================options=====================================
endOfLine: "lf"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {
margin: 42px;
}
================================================================================
`;
exports[`usingLf.css 1`] = `
====================================options=====================================
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {
margin: 42px;
}
================================================================================
`;
exports[`usingLf.css 2`] = `
====================================options=====================================
endOfLine: "cr"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {/*CR*/ margin: 42px;/*CR*/}/*CR*/
================================================================================
`;
exports[`usingLf.css 3`] = `
====================================options=====================================
endOfLine: "crlf"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {/*CR*/
margin: 42px;/*CR*/
}/*CR*/
================================================================================
`;
exports[`usingLf.css 4`] = `
====================================options=====================================
endOfLine: "lf"
parsers: ["css"]
printWidth: 80
| printWidth
=====================================input======================================
.foo {
margin: 42px;
}
=====================================output=====================================
.foo {
margin: 42px;
}
================================================================================
`;

View File

@ -1,4 +0,0 @@
run_spec(__dirname, ["css"]);
run_spec(__dirname, ["css"], { endOfLine: "cr" });
run_spec(__dirname, ["css"], { endOfLine: "crlf" });
run_spec(__dirname, ["css"], { endOfLine: "lf" });

View File

@ -1,3 +0,0 @@
.foo {
margin: 42px;
}

View File

@ -1,3 +0,0 @@
.foo {
margin: 42px;
}

View File

@ -1,137 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`usingCrlf.md 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file
testing line endings
================================================================================
`;
exports[`usingCrlf.md 2`] = `
====================================options=====================================
endOfLine: "cr"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file/*CR*//*CR*/testing line endings/*CR*/
================================================================================
`;
exports[`usingCrlf.md 3`] = `
====================================options=====================================
endOfLine: "crlf"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file/*CR*/
/*CR*/
testing line endings/*CR*/
================================================================================
`;
exports[`usingCrlf.md 4`] = `
====================================options=====================================
endOfLine: "lf"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file
testing line endings
================================================================================
`;
exports[`usingLf.md 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file
testing line endings
================================================================================
`;
exports[`usingLf.md 2`] = `
====================================options=====================================
endOfLine: "cr"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file/*CR*//*CR*/testing line endings/*CR*/
================================================================================
`;
exports[`usingLf.md 3`] = `
====================================options=====================================
endOfLine: "crlf"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file/*CR*/
/*CR*/
testing line endings/*CR*/
================================================================================
`;
exports[`usingLf.md 4`] = `
====================================options=====================================
endOfLine: "lf"
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# Markdown file
testing line endings
=====================================output=====================================
# Markdown file
testing line endings
================================================================================
`;

View File

@ -1,4 +0,0 @@
run_spec(__dirname, ["markdown"]);
run_spec(__dirname, ["markdown"], { endOfLine: "cr" });
run_spec(__dirname, ["markdown"], { endOfLine: "crlf" });
run_spec(__dirname, ["markdown"], { endOfLine: "lf" });

View File

@ -1,3 +0,0 @@
# Markdown file
testing line endings

View File

@ -1,3 +0,0 @@
# Markdown file
testing line endings

View File

@ -1,6 +1,6 @@
// @flow // @flow
// Example found at // Example found at
// https://github.com/sebmarkbage/art/blob/51ffce8164a555d652843241c2fdda52e186cbbd/parsers/svg/text.js#L137 // https://github.com/sebmarkbage/art/blob/51ffce8164a555d652843241c2fdda52e186cbbd/parsers/svg/text.js#L137
const evil_regex_as_a_string = "/[\s<>]*$/"; const evil_regex_as_a_string = "/[\s<>]*$/";
const error: string = 123; // Should be an error, but can't lex this file const error: string = 123; // Should be an error, but can't lex this file

View File

@ -1,66 +1,66 @@
export interface Environment1 extends GenericEnvironment< export interface Environment1 extends GenericEnvironment<
SomeType, SomeType,
AnotherType, AnotherType,
YetAnotherType, YetAnotherType,
> { > {
m(): void; m(): void;
}; };
export class Environment2 extends GenericEnvironment< export class Environment2 extends GenericEnvironment<
SomeType, SomeType,
AnotherType, AnotherType,
YetAnotherType, YetAnotherType,
DifferentType1, DifferentType1,
DifferentType2, DifferentType2,
DifferentType3, DifferentType3,
DifferentType4, DifferentType4,
> { > {
m() {}; m() {};
}; };
// Declare Interface Break // Declare Interface Break
declare interface ExtendsOne extends ASingleInterface { declare interface ExtendsOne extends ASingleInterface {
x: string; x: string;
} }
declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { declare interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName {
x: string; x: string;
} }
declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { declare interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 {
x: string; x: string;
} }
// Interface declaration break // Interface declaration break
interface ExtendsOne extends ASingleInterface { interface ExtendsOne extends ASingleInterface {
x: string; x: string;
} }
interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName { interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName {
x: string; x: string;
} }
interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 { interface ExtendsMany extends Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7 {
s: string; s: string;
} }
// Generic Types // Generic Types
interface ExtendsOne extends ASingleInterface<string> { interface ExtendsOne extends ASingleInterface<string> {
x: string; x: string;
} }
interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName<string> { interface ExtendsLarge extends ASingleInterfaceWithAReallyReallyReallyReallyLongName<string> {
x: string; x: string;
} }
interface ExtendsMany interface ExtendsMany
extends ASingleGenericInterface<Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7> { extends ASingleGenericInterface<Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7> {
x: string; x: string;
} }
interface ExtendsManyWithGenerics interface ExtendsManyWithGenerics
extends InterfaceOne, InterfaceTwo, ASingleGenericInterface<Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7>, InterfaceThree { extends InterfaceOne, InterfaceTwo, ASingleGenericInterface<Interface1, Interface2, Interface3, Interface4, Interface5, Interface6, Interface7>, InterfaceThree {
x: string; x: string;
} }
export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, ToBreakLineToBreakLineToBreakLine> {} export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTypeSomeLongTypeSomeLongType, ToBreakLineToBreakLineToBreakLine> {}

View File

@ -1,3 +1,3 @@
<div> <div>
Text Text
</div> </div>

View File

@ -1,131 +1,131 @@
<View <View
style={ style={
{ {
someVeryLongStyle1: "true", someVeryLongStyle1: "true",
someVeryLongStyle2: "true", someVeryLongStyle2: "true",
someVeryLongStyle3: "true", someVeryLongStyle3: "true",
someVeryLongStyle4: "true" someVeryLongStyle4: "true"
} }
} }
/>; />;
<View <View
style={ style={
[ [
{ {
someVeryLongStyle1: "true", someVeryLongStyle1: "true",
someVeryLongStyle2: "true", someVeryLongStyle2: "true",
someVeryLongStyle3: "true", someVeryLongStyle3: "true",
someVeryLongStyle4: "true" someVeryLongStyle4: "true"
} }
] ]
} }
/>; />;
<Something> <Something>
{() => ( {() => (
<SomethingElse> <SomethingElse>
<span /> <span />
</SomethingElse> </SomethingElse>
)} )}
</Something>; </Something>;
<Something> <Something>
{items.map(item => ( {items.map(item => (
<SomethingElse> <SomethingElse>
<span /> <span />
</SomethingElse> </SomethingElse>
))} ))}
</Something>; </Something>;
<Something> <Something>
{function() { {function() {
return ( return (
<SomethingElse> <SomethingElse>
<span /> <span />
</SomethingElse> </SomethingElse>
); );
}} }}
</Something>; </Something>;
<RadioListItem <RadioListItem
key={option} key={option}
imageSource={this.props.veryBigItemImageSourceFunc && imageSource={this.props.veryBigItemImageSourceFunc &&
this.props.veryBigItemImageSourceFunc(option)} this.props.veryBigItemImageSourceFunc(option)}
imageSize={this.props.veryBigItemImageSize} imageSize={this.props.veryBigItemImageSize}
imageView={this.props.veryBigItemImageViewFunc && imageView={this.props.veryBigItemImageViewFunc &&
this.props.veryBigItemImageViewFunc(option)} this.props.veryBigItemImageViewFunc(option)}
heading={this.props.displayTextFunc(option)} heading={this.props.displayTextFunc(option)}
value={option} value={option}
/>; />;
<ParentComponent prop={ <ParentComponent prop={
<Child> <Child>
test test
</Child> </Child>
}/>; }/>;
<BookingIntroPanel <BookingIntroPanel
prop="long_string_make_to_force_break" prop="long_string_make_to_force_break"
logClick={data => doLogClick("short", "short", data)} logClick={data => doLogClick("short", "short", data)}
/>; />;
<BookingIntroPanel <BookingIntroPanel
logClick={data => logClick={data =>
doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data) doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data)
} }
/>; />;
<BookingIntroPanel <BookingIntroPanel
logClick={data => { logClick={data => {
doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data) doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data)
}} }}
/>; />;
<Component <Component
onChange={( onChange={(
key: "possible_key_1" | "possible_key_2" | "possible_key_3", key: "possible_key_1" | "possible_key_2" | "possible_key_3",
value: string | Immutable.List<string>, value: string | Immutable.List<string>,
) => { ) => {
this.setState({ this.setState({
updatedTask: this.state.updatedTask.set(key, value) updatedTask: this.state.updatedTask.set(key, value)
}); });
}} }}
/>; />;
<BookingIntroPanel> <BookingIntroPanel>
{data => doLogClick("short", "short", data)} {data => doLogClick("short", "short", data)}
</BookingIntroPanel>; </BookingIntroPanel>;
<BookingIntroPanel> <BookingIntroPanel>
{data => {data =>
doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data) doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data)
} }
</BookingIntroPanel>; </BookingIntroPanel>;
<BookingIntroPanel> <BookingIntroPanel>
{data => { {data => {
doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data) doLogClick("long_name_long_name_long_name", "long_name_long_name_long_name", data)
}} }}
</BookingIntroPanel>; </BookingIntroPanel>;
<Component> <Component>
{( {(
key: "possible_key_1" | "possible_key_2" | "possible_key_3", key: "possible_key_1" | "possible_key_2" | "possible_key_3",
value: string | Immutable.List<string>, value: string | Immutable.List<string>,
) => { ) => {
this.setState({ this.setState({
updatedTask: this.state.updatedTask.set(key, value) updatedTask: this.state.updatedTask.set(key, value)
}); });
}} }}
</Component>; </Component>;
<SuspendyTree> <SuspendyTree>
<div style={{ height: 200, overflow: "scroll" }}> <div style={{ height: 200, overflow: "scroll" }}>
{Array(20) {Array(20)
.fill() .fill()
.map((_, i) => ( .map((_, i) => (
<h2 key={i}>{i + 1}</h2> <h2 key={i}>{i + 1}</h2>
))} ))}
</div> </div>
</SuspendyTree>; </SuspendyTree>;

View File

@ -1,5 +1,5 @@
const vscode = require("vscode"); const vscode = require("vscode");
const {getDir, getActiveFile, uint8arrayToString} = require("./utils"); const {getDir, getActiveFile, uint8arrayToString} = require("./utils");
let outChannel; let outChannel;
let _commands; let _commands;

View File

@ -1,10 +1,10 @@
<template> <template>
<div>{{foo}}</div> <div>{{foo}}</div>
</template> </template>
<script lang="ts"> <script lang="ts">
export default { export default {
computed: { foo( ): string { return "foo"; }, }, computed: { foo( ): string { return "foo"; }, },
} }
</script> </script>

View File

@ -1,7 +1,7 @@
<script lang="tsx"> <script lang="tsx">
import {VNode} from "vue" import {VNode} from "vue"
export default { export default {
computed: { foo( ):string { return "foo" }, }, computed: { foo( ):string { return "foo" }, },
render(h):VNode { return <div>{ this.foo }</div> }, render(h):VNode { return <div>{ this.foo }</div> },
} }
</script> </script>

View File

@ -58,7 +58,7 @@
'meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61' 'meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61'
'escaped newline \ 'escaped newline \
' '
'escaped carriage return \ 'escaped carriage return \
' '
'escaped \u2028 \' 'escaped \u2028 \'
'escaped \u2029 \' 'escaped \u2029 \'

View File

@ -1,4 +1,4 @@
class C { class C {
"foo"(); "foo"();
"bar"() { } "bar"() { }
} }

View File

@ -1,8 +1,8 @@
// @target: es6 // @target: es6
async function f() { async function f() {
<number> await 0; <number> await 0;
typeof await 0; typeof await 0;
void await 0; void await 0;
await void <string> typeof <number> void await 0; await void <string> typeof <number> void await 0;
await await 0; await await 0;
} }

View File

@ -1,11 +1,11 @@
class a { class a {
static b: any; static b: any;
} }
var b = (<any>a); var b = (<any>a);
var b = (<any>a).b; var b = (<any>a).b;
var b = (<any>a.b).c; var b = (<any>a.b).c;
var b = (<any>a.b()).c; var b = (<any>a.b()).c;
var b = (<any>new a); var b = (<any>new a);
var b = (<any>new a.b); var b = (<any>new a.b);
var b = (<any>new a).b var b = (<any>new a).b

View File

@ -1,30 +1,30 @@
var x : any = 0; var x : any = 0;
var z = <number> x; var z = <number> x;
var y = x + z; var y = x + z;
var a = <any>0; var a = <any>0;
var b = <boolean>true; var b = <boolean>true;
var s = <string>""; var s = <string>"";
var ar = <any[]>null; var ar = <any[]>null;
var f = <(res : number) => void>null; var f = <(res : number) => void>null;
declare class Point declare class Point
{ {
x: number; x: number;
y: number; y: number;
add(dx: number, dy: number): Point; add(dx: number, dy: number): Point;
mult(p: Point): Point; mult(p: Point): Point;
constructor(x: number, y: number); constructor(x: number, y: number);
} }
var p_cast = <Point> ({ var p_cast = <Point> ({
x: 0, x: 0,
y: 0, y: 0,
add: function(dx, dy) { add: function(dx, dy) {
return new Point(this.x + dx, this.y + dy); return new Point(this.x + dx, this.y + dy);
}, },
mult: function(p) { return p; } mult: function(p) { return p; }
}) })

View File

@ -1,16 +1,16 @@
// Regression test for #1002 // Regression test for #1002
// Before fix this code would cause infinite loop // Before fix this code would cause infinite loop
interface IObservable<T> { interface IObservable<T> {
n: IObservable<T[]>; // Needed, must be T[] n: IObservable<T[]>; // Needed, must be T[]
} }
// Needed // Needed
interface ISubject<T> extends IObservable<T> { } interface ISubject<T> extends IObservable<T> { }
interface Foo { x } interface Foo { x }
interface Bar { y } interface Bar { y }
var values: IObservable<Foo>; var values: IObservable<Foo>;
var values2: ISubject<Bar>; var values2: ISubject<Bar>;
values = values2; values = values2;

View File

@ -1,4 +1,4 @@
namespace hello.hi.world namespace hello.hi.world
{ {
function foo() {} function foo() {}
} }

View File

@ -1,5 +1,5 @@
// dot f g x = f(g(x)) // dot f g x = f(g(x))
var dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S; var dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S;
dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x)); dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x));
var id: <T>(x:T) => T; var id: <T>(x:T) => T;
var r23 = dot(id)(id); var r23 = dot(id)(id);

View File

@ -1,11 +1,11 @@
// @declaration: true // @declaration: true
module M { module M {
module P.Q { } // This shouldnt be emitted module P.Q { } // This shouldnt be emitted
} }
module M { module M {
export module R.S { } //This should be emitted export module R.S { } //This should be emitted
} }
module T.U { // This needs to be emitted module T.U { // This needs to be emitted
} }

View File

@ -1,37 +1,37 @@
var x = 0; var x = 0;
// errors // errors
1 ++; 1 ++;
(1)++; (1)++;
(1)--; (1)--;
++(1); ++(1);
--(1); --(1);
(1 + 2)++; (1 + 2)++;
(1 + 2)--; (1 + 2)--;
++(1 + 2); ++(1 + 2);
--(1 + 2); --(1 + 2);
(x + x)++; (x + x)++;
(x + x)--; (x + x)--;
++(x + x); ++(x + x);
--(x + x); --(x + x);
//OK //OK
x++; x++;
x--; x--;
++x; ++x;
--x; --x;
(x)++; (x)++;
--(x); --(x);
((x))++; ((x))++;
((x))--; ((x))--;
x[x++]++; x[x++]++;

View File

@ -1,3 +1,3 @@
interface Foo { interface Foo {
bar: number = 5; bar: number = 5;
} }

View File

@ -1,16 +1,16 @@
// @target: es5 // @target: es5
// @module: commonjs // @module: commonjs
// @declaration: true // @declaration: true
declare module "foo" { declare module "foo" {
export var before: C; export var before: C;
export default class C { export default class C {
method(): C; method(): C;
} }
export var after: C; export var after: C;
export var t: typeof C; export var t: typeof C;
} }

View File

@ -1,11 +1,11 @@
// overloading on arity not allowed // overloading on arity not allowed
interface C { interface C {
f<T>(): string; f<T>(): string;
f<T, U>(): string; f<T, U>(): string;
<T>(): string; <T>(): string;
<T, U>(): string; <T, U>(): string;
new <T>(): string; new <T>(): string;
new <T, U>(): string; new <T, U>(): string;
} }

View File

@ -1,16 +1,16 @@
function a() { function a() {
let global = 1; let global = 1;
} }
function b() { function b() {
class global {} class global {}
} }
namespace global { namespace global {
} }
function foo(global: number) { function foo(global: number) {
} }
let obj = { let obj = {
global: "123" global: "123"
} }

View File

@ -1,8 +1,8 @@
// These used to be indexers, now they are computed properties // These used to be indexers, now they are computed properties
interface I { interface I {
[x = '']: string; [x = '']: string;
} }
class C { class C {
[x = 0]: string [x = 0]: string
} }

View File

@ -1,18 +1,18 @@
// Repro from #13351 // Repro from #13351
type Meta<T, A> = { type Meta<T, A> = {
[P in keyof T]: { [P in keyof T]: {
value: T[P]; value: T[P];
also: A; also: A;
readonly children: Meta<T[P], A>; readonly children: Meta<T[P], A>;
}; };
} }
interface Input { interface Input {
x: string; x: string;
y: number; y: number;
} }
declare const output: Meta<Input, boolean>; declare const output: Meta<Input, boolean>;
const shouldFail: { important: boolean } = output.x.children; const shouldFail: { important: boolean } = output.x.children;

View File

@ -1,3 +1,3 @@
interface I { interface I {
public [a: string]: number; public [a: string]: number;
} }

View File

@ -1,153 +1,153 @@
//@declaration: true //@declaration: true
module m1 { module m1 {
export module m1_M1_public { export module m1_M1_public {
export class c1 { export class c1 {
} }
export function f1() { export function f1() {
return new c1; return new c1;
} }
export var v1 = c1; export var v1 = c1;
export var v2: c1; export var v2: c1;
} }
module m1_M2_private { module m1_M2_private {
export class c1 { export class c1 {
} }
export function f1() { export function f1() {
return new c1; return new c1;
} }
export var v1 = c1; export var v1 = c1;
export var v2: c1; export var v2: c1;
} }
//export declare module "m1_M3_public" { //export declare module "m1_M3_public" {
// export function f1(); // export function f1();
// export class c1 { // export class c1 {
// } // }
// export var v1: { new (): c1; }; // export var v1: { new (): c1; };
// export var v2: c1; // export var v2: c1;
//} //}
//declare module "m1_M4_private" { //declare module "m1_M4_private" {
// export function f1(); // export function f1();
// export class c1 { // export class c1 {
// } // }
// export var v1: { new (): c1; }; // export var v1: { new (): c1; };
// export var v2: c1; // export var v2: c1;
//} //}
import m1_im1_private = m1_M1_public; import m1_im1_private = m1_M1_public;
export var m1_im1_private_v1_public = m1_im1_private.c1; export var m1_im1_private_v1_public = m1_im1_private.c1;
export var m1_im1_private_v2_public = new m1_im1_private.c1(); export var m1_im1_private_v2_public = new m1_im1_private.c1();
export var m1_im1_private_v3_public = m1_im1_private.f1; export var m1_im1_private_v3_public = m1_im1_private.f1;
export var m1_im1_private_v4_public = m1_im1_private.f1(); export var m1_im1_private_v4_public = m1_im1_private.f1();
var m1_im1_private_v1_private = m1_im1_private.c1; var m1_im1_private_v1_private = m1_im1_private.c1;
var m1_im1_private_v2_private = new m1_im1_private.c1(); var m1_im1_private_v2_private = new m1_im1_private.c1();
var m1_im1_private_v3_private = m1_im1_private.f1; var m1_im1_private_v3_private = m1_im1_private.f1;
var m1_im1_private_v4_private = m1_im1_private.f1(); var m1_im1_private_v4_private = m1_im1_private.f1();
import m1_im2_private = m1_M2_private; import m1_im2_private = m1_M2_private;
export var m1_im2_private_v1_public = m1_im2_private.c1; export var m1_im2_private_v1_public = m1_im2_private.c1;
export var m1_im2_private_v2_public = new m1_im2_private.c1(); export var m1_im2_private_v2_public = new m1_im2_private.c1();
export var m1_im2_private_v3_public = m1_im2_private.f1; export var m1_im2_private_v3_public = m1_im2_private.f1;
export var m1_im2_private_v4_public = m1_im2_private.f1(); export var m1_im2_private_v4_public = m1_im2_private.f1();
var m1_im2_private_v1_private = m1_im2_private.c1; var m1_im2_private_v1_private = m1_im2_private.c1;
var m1_im2_private_v2_private = new m1_im2_private.c1(); var m1_im2_private_v2_private = new m1_im2_private.c1();
var m1_im2_private_v3_private = m1_im2_private.f1; var m1_im2_private_v3_private = m1_im2_private.f1;
var m1_im2_private_v4_private = m1_im2_private.f1(); var m1_im2_private_v4_private = m1_im2_private.f1();
//import m1_im3_private = require("m1_M3_public"); //import m1_im3_private = require("m1_M3_public");
//export var m1_im3_private_v1_public = m1_im3_private.c1; //export var m1_im3_private_v1_public = m1_im3_private.c1;
//export var m1_im3_private_v2_public = new m1_im3_private.c1(); //export var m1_im3_private_v2_public = new m1_im3_private.c1();
//export var m1_im3_private_v3_public = m1_im3_private.f1; //export var m1_im3_private_v3_public = m1_im3_private.f1;
//export var m1_im3_private_v4_public = m1_im3_private.f1(); //export var m1_im3_private_v4_public = m1_im3_private.f1();
//var m1_im3_private_v1_private = m1_im3_private.c1; //var m1_im3_private_v1_private = m1_im3_private.c1;
//var m1_im3_private_v2_private = new m1_im3_private.c1(); //var m1_im3_private_v2_private = new m1_im3_private.c1();
//var m1_im3_private_v3_private = m1_im3_private.f1; //var m1_im3_private_v3_private = m1_im3_private.f1;
//var m1_im3_private_v4_private = m1_im3_private.f1(); //var m1_im3_private_v4_private = m1_im3_private.f1();
//import m1_im4_private = require("m1_M4_private"); //import m1_im4_private = require("m1_M4_private");
//export var m1_im4_private_v1_public = m1_im4_private.c1; //export var m1_im4_private_v1_public = m1_im4_private.c1;
//export var m1_im4_private_v2_public = new m1_im4_private.c1(); //export var m1_im4_private_v2_public = new m1_im4_private.c1();
//export var m1_im4_private_v3_public = m1_im4_private.f1; //export var m1_im4_private_v3_public = m1_im4_private.f1;
//export var m1_im4_private_v4_public = m1_im4_private.f1(); //export var m1_im4_private_v4_public = m1_im4_private.f1();
//var m1_im4_private_v1_private = m1_im4_private.c1; //var m1_im4_private_v1_private = m1_im4_private.c1;
//var m1_im4_private_v2_private = new m1_im4_private.c1(); //var m1_im4_private_v2_private = new m1_im4_private.c1();
//var m1_im4_private_v3_private = m1_im4_private.f1; //var m1_im4_private_v3_private = m1_im4_private.f1;
//var m1_im4_private_v4_private = m1_im4_private.f1(); //var m1_im4_private_v4_private = m1_im4_private.f1();
export import m1_im1_public = m1_M1_public; export import m1_im1_public = m1_M1_public;
export import m1_im2_public = m1_M2_private; export import m1_im2_public = m1_M2_private;
//export import m1_im3_public = require("m1_M3_public"); //export import m1_im3_public = require("m1_M3_public");
//export import m1_im4_public = require("m1_M4_private"); //export import m1_im4_public = require("m1_M4_private");
} }
module glo_M1_public { module glo_M1_public {
export class c1 { export class c1 {
} }
export function f1() { export function f1() {
return new c1; return new c1;
} }
export var v1 = c1; export var v1 = c1;
export var v2: c1; export var v2: c1;
} }
declare module "glo_M2_public" { declare module "glo_M2_public" {
export function f1(); export function f1();
export class c1 { export class c1 {
} }
export var v1: { new (): c1; }; export var v1: { new (): c1; };
export var v2: c1; export var v2: c1;
} }
declare module "use_glo_M1_public" { declare module "use_glo_M1_public" {
import use_glo_M1_public = glo_M1_public; import use_glo_M1_public = glo_M1_public;
export var use_glo_M1_public_v1_public: { new (): use_glo_M1_public.c1; }; export var use_glo_M1_public_v1_public: { new (): use_glo_M1_public.c1; };
export var use_glo_M1_public_v2_public: typeof use_glo_M1_public; export var use_glo_M1_public_v2_public: typeof use_glo_M1_public;
export var use_glo_M1_public_v3_public: ()=> use_glo_M1_public.c1; export var use_glo_M1_public_v3_public: ()=> use_glo_M1_public.c1;
var use_glo_M1_public_v1_private: { new (): use_glo_M1_public.c1; }; var use_glo_M1_public_v1_private: { new (): use_glo_M1_public.c1; };
var use_glo_M1_public_v2_private: typeof use_glo_M1_public; var use_glo_M1_public_v2_private: typeof use_glo_M1_public;
var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1; var use_glo_M1_public_v3_private: () => use_glo_M1_public.c1;
import use_glo_M2_public = require("glo_M2_public"); import use_glo_M2_public = require("glo_M2_public");
export var use_glo_M2_public_v1_public: { new (): use_glo_M2_public.c1; }; export var use_glo_M2_public_v1_public: { new (): use_glo_M2_public.c1; };
export var use_glo_M2_public_v2_public: typeof use_glo_M2_public; export var use_glo_M2_public_v2_public: typeof use_glo_M2_public;
export var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1; export var use_glo_M2_public_v3_public: () => use_glo_M2_public.c1;
var use_glo_M2_public_v1_private: { new (): use_glo_M2_public.c1; }; var use_glo_M2_public_v1_private: { new (): use_glo_M2_public.c1; };
var use_glo_M2_public_v2_private: typeof use_glo_M2_public; var use_glo_M2_public_v2_private: typeof use_glo_M2_public;
var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1; var use_glo_M2_public_v3_private: () => use_glo_M2_public.c1;
module m2 { module m2 {
//import errorImport = require("glo_M2_public"); //import errorImport = require("glo_M2_public");
import nonerrorImport = glo_M1_public; import nonerrorImport = glo_M1_public;
module m5 { module m5 {
//import m5_errorImport = require("glo_M2_public"); //import m5_errorImport = require("glo_M2_public");
import m5_nonerrorImport = glo_M1_public; import m5_nonerrorImport = glo_M1_public;
} }
} }
} }
declare module "anotherParseError" { declare module "anotherParseError" {
module m2 { module m2 {
//declare module "abc" { //declare module "abc" {
//} //}
} }
module m2 { module m2 {
//module "abc2" { //module "abc2" {
//} //}
} }
//module "abc3" { //module "abc3" {
//} //}
} }
module m2 { module m2 {
//import m3 = require("use_glo_M1_public"); //import m3 = require("use_glo_M1_public");
module m4 { module m4 {
var a = 10; var a = 10;
//import m2 = require("use_glo_M1_public"); //import m2 = require("use_glo_M1_public");
} }
} }

View File

@ -1,26 +1,26 @@
declare var n; declare var n;
declare var m: string; declare var m: string;
declare function fn1(); declare function fn1();
declare function fn2(n: string): number; declare function fn2(n: string): number;
declare function fn3(n: string): number; declare function fn3(n: string): number;
declare function fn4(n: number, y: number): string; declare function fn4(n: number, y: number): string;
declare function fn5(x, y?); declare function fn5(x, y?);
declare function fn6(e?); declare function fn6(e?);
declare function fn7(x, y?, ...z); declare function fn7(x, y?, ...z);
declare function fn8(y?, ...z: number[]); declare function fn8(y?, ...z: number[]);
declare function fn9(...q: {}[]); declare function fn9(...q: {}[]);
declare function fn10<T>(...q: T[]); declare function fn10<T>(...q: T[]);
declare class cls { declare class cls {
constructor(); constructor();
method(): cls; method(): cls;
static static(p): number; static static(p): number;
static q; static q;
private fn(); private fn();
private static fns(); private static fns();
} }

View File

@ -1,7 +1,7 @@
abstract class A { abstract class A {
abstract get a(); abstract get a();
abstract get aa() { return 1; } abstract get aa() { return 1; }
abstract set b(x: string); abstract set b(x: string);
abstract set bb(x: string) {} abstract set bb(x: string) {}
} }

View File

@ -1,5 +1,5 @@
class abstract { class abstract {
foo() { return 1; } foo() { return 1; }
} }
new abstract; new abstract;

View File

@ -1,6 +1,6 @@
abstract class A { } abstract class A { }
var AAA: new() => A; var AAA: new() => A;
AAA = A; AAA = A;
AAA = "asdf"; AAA = "asdf";

View File

@ -1,13 +1,13 @@
var I: IConstructor; var I: IConstructor;
abstract class A { abstract class A {
x: number; x: number;
static y: number; static y: number;
} }
var AA: typeof A; var AA: typeof A;
AA = I; AA = I;
var AAA: typeof I; var AAA: typeof I;
AAA = A; AAA = A;

View File

@ -1,14 +1,14 @@
class A {} class A {}
abstract class B extends A {} abstract class B extends A {}
class C extends B {} class C extends B {}
var AA : typeof A = B; var AA : typeof A = B;
var BB : typeof B = A; var BB : typeof B = A;
var CC : typeof C = B; var CC : typeof C = B;
new AA; new AA;
new BB; new BB;
new CC; new CC;

View File

@ -1,9 +1,9 @@
abstract class foo { abstract class foo {
protected abstract test(); protected abstract test();
} }
class bar extends foo { class bar extends foo {
test() { test() {
} }
} }
var x = new bar(); var x = new bar();

View File

@ -1,16 +1,16 @@
class A { class A {
foo() {} foo() {}
} }
abstract class B extends A { abstract class B extends A {
abstract bar(); abstract bar();
} }
class C extends B { } class C extends B { }
abstract class D extends B {} abstract class D extends B {}
class E extends B { class E extends B {
bar() {} bar() {}
} }

View File

@ -1,17 +1,17 @@
class A {} class A {}
abstract class B extends A {} abstract class B extends A {}
function NewA(Factory: typeof A) { function NewA(Factory: typeof A) {
return new A; return new A;
} }
function NewB(Factory: typeof B) { function NewB(Factory: typeof B) {
return new B; return new B;
} }
NewA(A); NewA(A);
NewA(B); NewA(B);
NewB(A); NewB(A);
NewB(B); NewB(B);

View File

@ -1,25 +1,25 @@
abstract class A<T> { abstract class A<T> {
t: T; t: T;
abstract foo(): T; abstract foo(): T;
abstract bar(t: T); abstract bar(t: T);
} }
abstract class B<T> extends A {} abstract class B<T> extends A {}
class C<T> extends A {} class C<T> extends A {}
class D extends A {} class D extends A {}
class E<T> extends A { class E<T> extends A {
foo() { return this.t; } foo() { return this.t; }
} }
class F<T> extends A { class F<T> extends A {
bar(t : T) {} bar(t : T) {}
} }
class G<T> extends A { class G<T> extends A {
foo() { return this.t; } foo() { return this.t; }
bar(t: T) { } bar(t: T) { }
} }

View File

@ -1,7 +1,7 @@
export abstract class A {} export abstract class A {}
new A; new A;
new myA; new myA;

View File

@ -1,7 +1,7 @@
export abstract class A {} export abstract class A {}
export class B extends A {} export class B extends A {}
new M.A; new M.A;
new M.B; new M.B;

View File

@ -1,21 +1,21 @@
abstract class A {} abstract class A {}
abstract class B extends A {} abstract class B extends A {}
class C extends A {} class C extends A {}
abstract class AA { abstract class AA {
abstract foo(); abstract foo();
} }
abstract class BB extends AA {} abstract class BB extends AA {}
class CC extends AA {} class CC extends AA {}
class DD extends BB {} class DD extends BB {}
abstract class EE extends BB {} abstract class EE extends BB {}
class FF extends CC {} class FF extends CC {}
abstract class GG extends CC {} abstract class GG extends CC {}

View File

@ -1,19 +1,19 @@
abstract class A {} abstract class A {}
class B extends A {} class B extends A {}
abstract class C extends B {} abstract class C extends B {}
new A; new A;
new A(1); new A(1);
new B; new B;
new C; new C;
var a : A; var a : A;
var b : B; var b : B;
var c : C; var c : C;
a = new B; a = new B;
b = new B; b = new B;
c = new B; c = new B;

View File

@ -1,50 +1,50 @@
class A { class A {
} }
abstract class B { abstract class B {
foo(): number { return this.bar(); } foo(): number { return this.bar(); }
abstract bar() : number; abstract bar() : number;
} }
new B; new B;
var BB: typeof B = B; var BB: typeof B = B;
var AA: typeof A = BB; var AA: typeof A = BB;
new AA; new AA;
function constructB(Factory : typeof B) { function constructB(Factory : typeof B) {
new Factory; new Factory;
} }
var BB = B; var BB = B;
new BB; new BB;
var x : any = C; var x : any = C;
new x; new x;
class C extends B { } class C extends B { }
abstract class D extends B { } abstract class D extends B { }
class E extends B { class E extends B {
bar() { return 1; } bar() { return 1; }
} }
abstract class F extends B { abstract class F extends B {
abstract foo() : number; abstract foo() : number;
bar() { return 2; } bar() { return 2; }
} }
abstract class G { abstract class G {
abstract qux(x : number) : string; abstract qux(x : number) : string;
abstract qux() : number; abstract qux() : number;
y : number; y : number;
abstract quz(x : number, y : string) : boolean; abstract quz(x : number, y : string) : boolean;
abstract nom(): boolean; abstract nom(): boolean;
nom(x : number): boolean; nom(x : number): boolean;
} }
class H { class H {
abstract baz() : number; abstract baz() : number;
} }

View File

@ -1,7 +1,7 @@
class A { class A {
abstract foo(); abstract foo();
} }
class B { class B {
abstract foo() {} abstract foo() {}
} }

View File

@ -1,3 +1,3 @@
abstract class A { abstract class A {
abstract foo() {} abstract foo() {}
} }

View File

@ -1,15 +1,15 @@
abstract class A { abstract class A {
abstract foo_a(); abstract foo_a();
public abstract foo_b(); public abstract foo_b();
protected abstract foo_c(); protected abstract foo_c();
private abstract foo_d(); private abstract foo_d();
abstract public foo_bb(); abstract public foo_bb();
abstract protected foo_cc(); abstract protected foo_cc();
abstract private foo_dd(); abstract private foo_dd();
abstract static foo_d(); abstract static foo_d();
static abstract foo_e(); static abstract foo_e();
} }

View File

@ -1,24 +1,24 @@
abstract class A { abstract class A {
abstract foo(); abstract foo();
abstract foo() : number; abstract foo() : number;
abstract foo(); abstract foo();
abstract bar(); abstract bar();
bar(); bar();
abstract bar(); abstract bar();
abstract baz(); abstract baz();
baz(); baz();
abstract baz(); abstract baz();
baz() {} baz() {}
qux(); qux();
} }
abstract class B { abstract class B {
abstract foo() : number; abstract foo() : number;
abstract foo(); abstract foo();
x : number; x : number;
abstract foo(); abstract foo();
abstract foo(); abstract foo();
} }

View File

@ -1,23 +1,23 @@
class A { class A {
foo() {} foo() {}
} }
abstract class B extends A { abstract class B extends A {
abstract foo(); abstract foo();
} }
abstract class AA { abstract class AA {
foo() {} foo() {}
abstract bar(); abstract bar();
} }
abstract class BB extends AA { abstract class BB extends AA {
abstract foo(); abstract foo();
bar () {} bar () {}
} }
class CC extends BB {} class CC extends BB {}
class DD extends BB { class DD extends BB {
foo() {} foo() {}
} }

View File

@ -1,13 +1,13 @@
abstract class A { abstract class A {
abstract x : number; abstract x : number;
public abstract y : number; public abstract y : number;
protected abstract z : number; protected abstract z : number;
private abstract w : number; private abstract w : number;
abstract m: () => void; abstract m: () => void;
abstract foo_x() : number; abstract foo_x() : number;
public abstract foo_y() : number; public abstract foo_y() : number;
protected abstract foo_z() : number; protected abstract foo_z() : number;
private abstract foo_w() : number; private abstract foo_w() : number;
} }

View File

@ -1,12 +1,12 @@
abstract class A {} abstract class A {}
abstract abstract
class B {} class B {}
abstract abstract
class C {} class C {}
new A; new A;
new B; new B;
new C; new C;

View File

@ -1,25 +1,25 @@
class A { class A {
foo() { return 1; } foo() { return 1; }
} }
abstract class B extends A { abstract class B extends A {
abstract foo(); abstract foo();
bar() { super.foo(); } bar() { super.foo(); }
baz() { return this.foo; } baz() { return this.foo; }
} }
class C extends B { class C extends B {
foo() { return 2; } foo() { return 2; }
qux() { return super.foo() || super.foo; } qux() { return super.foo() || super.foo; }
norf() { return super.bar(); } norf() { return super.bar(); }
} }
class AA { class AA {
foo() { return 1; } foo() { return 1; }
bar() { return this.foo(); } bar() { return this.foo(); }
} }
abstract class BB extends AA { abstract class BB extends AA {
abstract foo(); abstract foo();
} }

View File

@ -1,17 +1,17 @@
abstract class A { abstract class A {
abstract foo() : number; abstract foo() : number;
} }
class B extends A { class B extends A {
foo() { return 1; } foo() { return 1; }
} }
abstract class C extends A { abstract class C extends A {
abstract foo() : number; abstract foo() : number;
} }
var a = new B; var a = new B;
a.foo(); a.foo();
a = new C; a = new C;
a.foo(); a.foo();

View File

@ -1,27 +1,27 @@
class A { class A {
abstract foo(); abstract foo();
} }
class B extends A {} class B extends A {}
abstract class C extends A {} abstract class C extends A {}
class D extends A { class D extends A {
foo() {} foo() {}
} }
abstract class E extends A { abstract class E extends A {
foo() {} foo() {}
} }
abstract class AA { abstract class AA {
abstract foo(); abstract foo();
} }
class BB extends AA {} class BB extends AA {}
abstract class CC extends AA {} abstract class CC extends AA {}
class DD extends AA { class DD extends AA {
foo() {} foo() {}
} }

View File

@ -1,7 +1,7 @@
class C { foo: string; } class C { foo: string; }
var c: C; var c: C;
var r = c.toString(); var r = c.toString();
var r2 = c.hasOwnProperty(''); var r2 = c.hasOwnProperty('');
var o: Object = c; var o: Object = c;
var o2: {} = c; var o2: {} = c;

View File

@ -1,31 +1,31 @@
class C { class C {
foo: string; foo: string;
thing() { } thing() { }
static other() { } static other() { }
} }
class D extends C { class D extends C {
bar: string; bar: string;
} }
var d: D; var d: D;
var r = d.foo; var r = d.foo;
var r2 = d.bar; var r2 = d.bar;
var r3 = d.thing(); var r3 = d.thing();
var r4 = D.other(); var r4 = D.other();
class C2<T> { class C2<T> {
foo: T; foo: T;
thing(x: T) { } thing(x: T) { }
static other<T>(x: T) { } static other<T>(x: T) { }
} }
class D2<T> extends C2<T> { class D2<T> extends C2<T> {
bar: string; bar: string;
} }
var d2: D2<string>; var d2: D2<string>;
var r5 = d2.foo; var r5 = d2.foo;
var r6 = d2.bar; var r6 = d2.bar;
var r7 = d2.thing(''); var r7 = d2.thing('');
var r8 = D2.other(1); var r8 = D2.other(1);

View File

@ -1,11 +1,11 @@
class C extends E { foo: string; } // error class C extends E { foo: string; } // error
class D extends C { bar: string; } class D extends C { bar: string; }
class E extends D { baz: number; } class E extends D { baz: number; }
class C2<T> extends E2<T> { foo: T; } // error class C2<T> extends E2<T> { foo: T; } // error
class D2<T> extends C2<T> { bar: T; } class D2<T> extends C2<T> { bar: T; }
class E2<T> extends D2<T> { baz: T; } class E2<T> extends D2<T> { baz: T; }

View File

@ -1,7 +1,7 @@
class Base<T> { class Base<T> {
foo: T; foo: T;
} }
class Derived extends Base<string> { class Derived extends Base<string> {
foo: any; foo: any;
} }

View File

@ -1,3 +1,3 @@
function foo() { function foo() {
class C { } class C { }
} }

View File

@ -1,10 +1,10 @@
var x = class C { var x = class C {
} }
var y = { var y = {
foo: class C2 { foo: class C2 {
} }
} }
var z = class C4 { var z = class C4 {
} }

View File

@ -1,11 +1,11 @@
class C { class C {
constructor(x = this) { } constructor(x = this) { }
} }
class D<T> { class D<T> {
constructor(x = this) { } constructor(x = this) { }
} }
class E<T> { class E<T> {
constructor(public x = this) { } constructor(public x = this) { }
} }

View File

@ -1,20 +1,20 @@
class C { class C {
constructor(x); constructor(x);
constructor(x = 1) { constructor(x = 1) {
var y = x; var y = x;
} }
} }
class D<T> { class D<T> {
constructor(x); constructor(x);
constructor(x:T = null) { constructor(x:T = null) {
var y = x; var y = x;
} }
} }
class E<T extends Date> { class E<T extends Date> {
constructor(x); constructor(x);
constructor(x: T = null) { constructor(x: T = null) {
var y = x; var y = x;
} }
} }

View File

@ -1,20 +1,20 @@
class C { class C {
constructor(x); constructor(x);
constructor(public x: string = 1) { constructor(public x: string = 1) {
var y = x; var y = x;
} }
} }
class D<T, U> { class D<T, U> {
constructor(x: T, y: U); constructor(x: T, y: U);
constructor(x: T = 1, public y: U = x) { constructor(x: T = 1, public y: U = x) {
var z = x; var z = x;
} }
} }
class E<T extends Date> { class E<T extends Date> {
constructor(x); constructor(x);
constructor(x: T = new Date()) { constructor(x: T = new Date()) {
var y = x; var y = x;
} }
} }

View File

@ -1,13 +1,13 @@
class C { class C {
foo: string; foo: string;
constructor(x = 1); constructor(x = 1);
constructor() { constructor() {
} }
} }
class D<T> { class D<T> {
foo: string; foo: string;
constructor(x = 1); constructor(x = 1);
constructor() { constructor() {
} }
} }

View File

@ -1,13 +1,13 @@
class C { class C {
foo: string; foo: string;
constructor(x?, y?: any[]); constructor(x?, y?: any[]);
constructor() { constructor() {
} }
} }
class D<T> { class D<T> {
foo: string; foo: string;
constructor(x?, y?: any[]); constructor(x?, y?: any[]);
constructor() { constructor() {
} }
} }

View File

@ -1,20 +1,20 @@
class C { class C {
y: string; y: string;
constructor(private x: string, protected z: string) { } constructor(private x: string, protected z: string) { }
} }
var c: C; var c: C;
var r = c.y; var r = c.y;
var r2 = c.x; // error var r2 = c.x; // error
var r3 = c.z; // error var r3 = c.z; // error
class D<T> { class D<T> {
y: T; y: T;
constructor(a: T, private x: T, protected z: T) { } constructor(a: T, private x: T, protected z: T) { }
} }
var d: D<string>; var d: D<string>;
var r = d.y; var r = d.y;
var r2 = d.x; // error var r2 = d.x; // error
var r3 = d.a; // error var r3 = d.a; // error
var r4 = d.z; // error var r4 = d.z; // error

View File

@ -1,31 +1,31 @@
class C { class C {
y: number; y: number;
constructor(y: number) { } // ok constructor(y: number) { } // ok
} }
var c: C; var c: C;
var r = c.y; var r = c.y;
class D { class D {
y: number; y: number;
constructor(public y: number) { } constructor(public y: number) { }
} }
var d: D; var d: D;
var r2 = d.y; var r2 = d.y;
class E { class E {
y: number; y: number;
constructor(private y: number) { } constructor(private y: number) { }
} }
var e: E; var e: E;
var r3 = e.y; // error var r3 = e.y; // error
class F { class F {
y: number; y: number;
constructor(protected y: number) { } constructor(protected y: number) { }
} }
var f: F; var f: F;
var r4 = f.y; // error var r4 = f.y; // error

View File

@ -1,5 +1,5 @@
// @declaration: true // @declaration: true
class C { class C {
constructor(readonly x: number) {} constructor(readonly x: number) {}
} }

View File

@ -1,38 +1,38 @@
// Tests that readonly parameter properties behave like regular readonly properties // Tests that readonly parameter properties behave like regular readonly properties
class A { class A {
constructor(readonly x: number) { constructor(readonly x: number) {
this.x = 0; this.x = 0;
} }
} }
class B extends A { class B extends A {
constructor(x: number) { constructor(x: number) {
super(x); super(x);
// Fails, x is readonly // Fails, x is readonly
this.x = 1; this.x = 1;
} }
} }
class C extends A { class C extends A {
// This is the usual behavior of readonly properties: // This is the usual behavior of readonly properties:
// if one is redeclared in a base class, then it can be assigned to. // if one is redeclared in a base class, then it can be assigned to.
constructor(readonly x: number) { constructor(readonly x: number) {
super(x); super(x);
this.x = 1; this.x = 1;
} }
} }
class D { class D {
constructor(private readonly x: number) { constructor(private readonly x: number) {
this.x = 0; this.x = 0;
} }
} }
// Fails, can't redeclare readonly property // Fails, can't redeclare readonly property
class E extends D { class E extends D {
constructor(readonly x: number) { constructor(readonly x: number) {
super(x); super(x);
this.x = 1; this.x = 1;
} }
} }

View File

@ -1,13 +1,13 @@
class C { class C {
constructor(readonly x: number) {} constructor(readonly x: number) {}
} }
new C(1).x = 2; new C(1).x = 2;
class E { class E {
constructor(readonly public x: number) {} constructor(readonly public x: number) {}
} }
class F { class F {
constructor(private readonly x: number) {} constructor(private readonly x: number) {}
} }
new F(1).x; new F(1).x;

View File

@ -1,4 +1,4 @@
class C { class C {
readonly readonly x: number; readonly readonly x: number;
constructor(readonly readonly y: number) {} constructor(readonly readonly y: number) {}
} }

Some files were not shown because too many files have changed in this diff Show More