Skip to content

Commit 9f087cb

Browse files
committed
Merge pull request #8941 from Microsoft/controlFlowPropertyDeclarations
Create control flows for property declarations
2 parents 166f399 + 706683d commit 9f087cb

5 files changed

+1112
-0
lines changed

src/compiler/binder.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,8 @@ namespace ts {
11421142

11431143
case SyntaxKind.ModuleBlock:
11441144
return ContainerFlags.IsControlFlowContainer;
1145+
case SyntaxKind.PropertyDeclaration:
1146+
return (<PropertyDeclaration>node).initializer ? ContainerFlags.IsControlFlowContainer : 0;
11451147

11461148
case SyntaxKind.CatchClause:
11471149
case SyntaxKind.ForStatement:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
//// [controlFlowPropertyDeclarations.ts]
2+
// Repro from ##8913
3+
4+
declare var require:any;
5+
6+
var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig');
7+
8+
// Populate property map with ReactJS's attribute and property mappings
9+
// TODO handle/use .Properties value eg: MUST_USE_PROPERTY is not HTML attr
10+
for (var propname in HTMLDOMPropertyConfig.Properties) {
11+
if (!HTMLDOMPropertyConfig.Properties.hasOwnProperty(propname)) {
12+
continue;
13+
}
14+
15+
var mapFrom = HTMLDOMPropertyConfig.DOMAttributeNames[propname] || propname.toLowerCase();
16+
}
17+
18+
/**
19+
* Repeats a string a certain number of times.
20+
* Also: the future is bright and consists of native string repetition:
21+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
22+
*
23+
* @param {string} string String to repeat
24+
* @param {number} times Number of times to repeat string. Integer.
25+
* @see http://jsperf.com/string-repeater/2
26+
*/
27+
function repeatString(string, times) {
28+
if (times === 1) {
29+
return string;
30+
}
31+
if (times < 0) { throw new Error(); }
32+
var repeated = '';
33+
while (times) {
34+
if (times & 1) {
35+
repeated += string;
36+
}
37+
if (times >>= 1) {
38+
string += string;
39+
}
40+
}
41+
return repeated;
42+
}
43+
44+
/**
45+
* Determine if the string ends with the specified substring.
46+
*
47+
* @param {string} haystack String to search in
48+
* @param {string} needle String to search for
49+
* @return {boolean}
50+
*/
51+
function endsWith(haystack, needle) {
52+
return haystack.slice(-needle.length) === needle;
53+
}
54+
55+
/**
56+
* Trim the specified substring off the string. If the string does not end
57+
* with the specified substring, this is a no-op.
58+
*
59+
* @param {string} haystack String to search in
60+
* @param {string} needle String to search for
61+
* @return {string}
62+
*/
63+
function trimEnd(haystack, needle) {
64+
return endsWith(haystack, needle)
65+
? haystack.slice(0, -needle.length)
66+
: haystack;
67+
}
68+
69+
/**
70+
* Convert a hyphenated string to camelCase.
71+
*/
72+
function hyphenToCamelCase(string) {
73+
return string.replace(/-(.)/g, function(match, chr) {
74+
return chr.toUpperCase();
75+
});
76+
}
77+
78+
/**
79+
* Determines if the specified string consists entirely of whitespace.
80+
*/
81+
function isEmpty(string) {
82+
return !/[^\s]/.test(string);
83+
}
84+
85+
/**
86+
* Determines if the CSS value can be converted from a
87+
* 'px' suffixed string to a numeric value
88+
*
89+
* @param {string} value CSS property value
90+
* @return {boolean}
91+
*/
92+
function isConvertiblePixelValue(value) {
93+
return /^\d+px$/.test(value);
94+
}
95+
96+
export class HTMLtoJSX {
97+
private output: string;
98+
private level: number;
99+
private _inPreTag: boolean;
100+
101+
102+
/**
103+
* Handles processing of the specified text node
104+
*
105+
* @param {TextNode} node
106+
*/
107+
_visitText = (node) => {
108+
var parentTag = node.parentNode && node.parentNode.tagName.toLowerCase();
109+
if (parentTag === 'textarea' || parentTag === 'style') {
110+
// Ignore text content of textareas and styles, as it will have already been moved
111+
// to a "defaultValue" attribute and "dangerouslySetInnerHTML" attribute respectively.
112+
return;
113+
}
114+
115+
var text = ''
116+
117+
if (this._inPreTag) {
118+
// If this text is contained within a <pre>, we need to ensure the JSX
119+
// whitespace coalescing rules don't eat the whitespace. This means
120+
// wrapping newlines and sequences of two or more spaces in variables.
121+
text = text
122+
.replace(/\r/g, '')
123+
.replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) {
124+
return '{' + JSON.stringify(whitespace) + '}';
125+
});
126+
} else {
127+
// If there's a newline in the text, adjust the indent level
128+
if (text.indexOf('\n') > -1) {
129+
}
130+
}
131+
this.output += text;
132+
}
133+
134+
135+
136+
};
137+
138+
/**
139+
* Handles parsing of inline styles
140+
*/
141+
export class StyleParser {
142+
styles = {};
143+
toJSXString = () => {
144+
for (var key in this.styles) {
145+
if (!this.styles.hasOwnProperty(key)) {
146+
}
147+
}
148+
}
149+
}
150+
151+
//// [controlFlowPropertyDeclarations.js]
152+
// Repro from ##8913
153+
"use strict";
154+
var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig');
155+
// Populate property map with ReactJS's attribute and property mappings
156+
// TODO handle/use .Properties value eg: MUST_USE_PROPERTY is not HTML attr
157+
for (var propname in HTMLDOMPropertyConfig.Properties) {
158+
if (!HTMLDOMPropertyConfig.Properties.hasOwnProperty(propname)) {
159+
continue;
160+
}
161+
var mapFrom = HTMLDOMPropertyConfig.DOMAttributeNames[propname] || propname.toLowerCase();
162+
}
163+
/**
164+
* Repeats a string a certain number of times.
165+
* Also: the future is bright and consists of native string repetition:
166+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
167+
*
168+
* @param {string} string String to repeat
169+
* @param {number} times Number of times to repeat string. Integer.
170+
* @see http://jsperf.com/string-repeater/2
171+
*/
172+
function repeatString(string, times) {
173+
if (times === 1) {
174+
return string;
175+
}
176+
if (times < 0) {
177+
throw new Error();
178+
}
179+
var repeated = '';
180+
while (times) {
181+
if (times & 1) {
182+
repeated += string;
183+
}
184+
if (times >>= 1) {
185+
string += string;
186+
}
187+
}
188+
return repeated;
189+
}
190+
/**
191+
* Determine if the string ends with the specified substring.
192+
*
193+
* @param {string} haystack String to search in
194+
* @param {string} needle String to search for
195+
* @return {boolean}
196+
*/
197+
function endsWith(haystack, needle) {
198+
return haystack.slice(-needle.length) === needle;
199+
}
200+
/**
201+
* Trim the specified substring off the string. If the string does not end
202+
* with the specified substring, this is a no-op.
203+
*
204+
* @param {string} haystack String to search in
205+
* @param {string} needle String to search for
206+
* @return {string}
207+
*/
208+
function trimEnd(haystack, needle) {
209+
return endsWith(haystack, needle)
210+
? haystack.slice(0, -needle.length)
211+
: haystack;
212+
}
213+
/**
214+
* Convert a hyphenated string to camelCase.
215+
*/
216+
function hyphenToCamelCase(string) {
217+
return string.replace(/-(.)/g, function (match, chr) {
218+
return chr.toUpperCase();
219+
});
220+
}
221+
/**
222+
* Determines if the specified string consists entirely of whitespace.
223+
*/
224+
function isEmpty(string) {
225+
return !/[^\s]/.test(string);
226+
}
227+
/**
228+
* Determines if the CSS value can be converted from a
229+
* 'px' suffixed string to a numeric value
230+
*
231+
* @param {string} value CSS property value
232+
* @return {boolean}
233+
*/
234+
function isConvertiblePixelValue(value) {
235+
return /^\d+px$/.test(value);
236+
}
237+
var HTMLtoJSX = (function () {
238+
function HTMLtoJSX() {
239+
var _this = this;
240+
/**
241+
* Handles processing of the specified text node
242+
*
243+
* @param {TextNode} node
244+
*/
245+
this._visitText = function (node) {
246+
var parentTag = node.parentNode && node.parentNode.tagName.toLowerCase();
247+
if (parentTag === 'textarea' || parentTag === 'style') {
248+
// Ignore text content of textareas and styles, as it will have already been moved
249+
// to a "defaultValue" attribute and "dangerouslySetInnerHTML" attribute respectively.
250+
return;
251+
}
252+
var text = '';
253+
if (_this._inPreTag) {
254+
// If this text is contained within a <pre>, we need to ensure the JSX
255+
// whitespace coalescing rules don't eat the whitespace. This means
256+
// wrapping newlines and sequences of two or more spaces in variables.
257+
text = text
258+
.replace(/\r/g, '')
259+
.replace(/( {2,}|\n|\t|\{|\})/g, function (whitespace) {
260+
return '{' + JSON.stringify(whitespace) + '}';
261+
});
262+
}
263+
else {
264+
// If there's a newline in the text, adjust the indent level
265+
if (text.indexOf('\n') > -1) {
266+
}
267+
}
268+
_this.output += text;
269+
};
270+
}
271+
return HTMLtoJSX;
272+
}());
273+
exports.HTMLtoJSX = HTMLtoJSX;
274+
;
275+
/**
276+
* Handles parsing of inline styles
277+
*/
278+
var StyleParser = (function () {
279+
function StyleParser() {
280+
var _this = this;
281+
this.styles = {};
282+
this.toJSXString = function () {
283+
for (var key in _this.styles) {
284+
if (!_this.styles.hasOwnProperty(key)) {
285+
}
286+
}
287+
};
288+
}
289+
return StyleParser;
290+
}());
291+
exports.StyleParser = StyleParser;

0 commit comments

Comments
 (0)