Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java

Issue 460163002: Handle property definition by {cr|Object}.defineProperty() in compiler pass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@C_compiler_pass
Patch Set: define property on prototype, also minor nits Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package com.google.javascript.jscomp; 5 package com.google.javascript.jscomp;
6 6
7 /** 7 /**
8 * Tests {@link ChromePass}. 8 * Tests {@link ChromePass}.
9 */ 9 */
10 public class ChromePassTest extends CompilerTestCase { 10 public class ChromePassTest extends CompilerTestCase {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 public void testCrDefineInvalidSecondArgument() throws Exception { 177 public void testCrDefineInvalidSecondArgument() throws Exception {
178 test("cr.define('namespace', 42)\n", 178 test("cr.define('namespace', 42)\n",
179 null, ChromePass.CR_DEFINE_INVALID_SECOND_ARGUMENT); 179 null, ChromePass.CR_DEFINE_INVALID_SECOND_ARGUMENT);
180 } 180 }
181 181
182 public void testCrDefineInvalidReturnInFunction() throws Exception { 182 public void testCrDefineInvalidReturnInFunction() throws Exception {
183 test("cr.define('namespace', function() {})\n", 183 test("cr.define('namespace', function() {})\n",
184 null, ChromePass.CR_DEFINE_INVALID_RETURN_IN_FUNCTION); 184 null, ChromePass.CR_DEFINE_INVALID_RETURN_IN_FUNCTION);
185 } 185 }
186 186
187 public void testObjectDefinePropertyDefinesUnquotedProperty() throws Excepti on {
188 test(
189 "Object.defineProperty(a.b, 'c', {});",
190 "Object.defineProperty(a.b, 'c', {});\n" +
191 "/** @type {?} */\n" +
192 "a.b.c;");
193 }
194
195 public void testCrDefinePropertyDefinesUnquotedPropertyWithStringTypeForProp ertyKindAttr()
196 throws Exception {
197 test(
198 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.ATTR);",
199 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.ATTR);\n" +
200 "/** @type {string} */\n" +
201 "a.prototype.c;");
202 }
203
204 public void testCrDefinePropertyDefinesUnquotedPropertyWithBooleanTypeForPro pertyKindBoolAttr()
205 throws Exception {
206 test(
207 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.BOOL_ATTR);",
208 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.BOOL_ATTR);\n" +
209 "/** @type {boolean} */\n" +
210 "a.prototype.c;");
211 }
212
213 public void testCrDefinePropertyDefinesUnquotedPropertyWithAnyTypeForPropert yKindJs()
214 throws Exception {
215 test(
216 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.JS);",
217 "cr.defineProperty(a.prototype, 'c', cr.PropertyKind.JS);\n" +
218 "/** @type {?} */\n" +
219 "a.prototype.c;");
220 }
221
222 public void testCrDefinePropertyDefinesUnquotedPropertyOnPrototypeWhenFuncti onIsPassed()
223 throws Exception {
224 test(
225 "cr.defineProperty(a, 'c', cr.PropertyKind.JS);",
226 "cr.defineProperty(a, 'c', cr.PropertyKind.JS);\n" +
227 "/** @type {?} */\n" +
228 "a.prototype.c;");
229 }
230
231 public void testCrDefinePropertyInvalidPropertyKind()
232 throws Exception {
233 test(
234 "cr.defineProperty(a.b, 'c', cr.PropertyKind.INEXISTENT_KIND);",
235 null, ChromePass.CR_DEFINE_PROPERTY_INVALID_PROPERTY_KIND);
236 }
237
187 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698