| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package com.google.javascript.jscomp; |
| 19 |
|
| 20 |
import com.google.javascript.jscomp.CompilerOptions.LanguageMode; |
| 21 |
import com.google.javascript.rhino.testing.BaseJSTypeTestCase; |
| 22 |
|
| 23 |
abstract class CompilerTypeTestCase extends BaseJSTypeTestCase { |
| 24 |
|
| 25 |
static final String ACTIVE_X_OBJECT_DEF = |
| 26 |
"/**\n" + |
| 27 |
" * @param {string} progId\n" + |
| 28 |
" * @param {string=} opt_location\n" + |
| 29 |
" * @constructor\n" + |
| 30 |
" * @see http://msdn.microsoft.com/en-us/library/7sw4ddf8.aspx\n" + |
| 31 |
" */\n" + |
| 32 |
"function ActiveXObject(progId, opt_location) {}\n"; |
| 33 |
|
| 34 |
static final String CLOSURE_DEFS = |
| 35 |
"var goog = {};" + |
| 36 |
"goog.inherits = function(x, y) {};" + |
| 37 |
"/** @type {!Function} */ goog.abstractMethod = function() {};" + |
| 38 |
"goog.isArray = function(x) {};" + |
| 39 |
"goog.isDef = function(x) {};" + |
| 40 |
"goog.isFunction = function(x) {};" + |
| 41 |
"goog.isNull = function(x) {};" + |
| 42 |
"goog.isString = function(x) {};" + |
| 43 |
"goog.isObject = function(x) {};" + |
| 44 |
"goog.isDefAndNotNull = function(x) {};" + |
| 45 |
"goog.array = {};" + |
| 46 |
|
| 47 |
"/**\n" + |
| 48 |
" * @typedef {Array|{length: number}}\n" + |
| 49 |
" */\n" + |
| 50 |
"goog.array.ArrayLike;" + |
| 51 |
"/**\n" + |
| 52 |
" * @param {Array.<T>|{length:number}} arr\n" + |
| 53 |
" * @param {function(this:S, T, number, goog.array.ArrayLike):boolean} f\n" + |
| 54 |
" * @param {S=} opt_obj\n" + |
| 55 |
" * @return {!Array.<T>}\n" + |
| 56 |
" * @template T,S\n" + |
| 57 |
" */" + |
| 58 |
"goog.array.filter = function(arr, f, opt_obj){};" + |
| 59 |
"goog.asserts = {};" + |
| 60 |
"/** @return {*} */ goog.asserts.assert = function(x) { return x; };"; |
| 61 |
|
| 62 |
|
| 63 |
static final String DEFAULT_EXTERNS = |
| 64 |
"/** @constructor \n * @param {*=} opt_value */ " + |
| 65 |
"function Object(opt_value) {}" + |
| 66 |
"/** @constructor \n * @param {*} var_args */ " + |
| 67 |
"function Function(var_args) {}" + |
| 68 |
"/** @type {!Function} */ Function.prototype.apply;" + |
| 69 |
"/** @type {!Function} */ Function.prototype.bind;" + |
| 70 |
"/** @type {!Function} */ Function.prototype.call;" + |
| 71 |
"/** @constructor \n * @param {*=} arg \n @return {string} */" + |
| 72 |
"function String(arg) {}" + |
| 73 |
"/** @param {number} sliceArg */\n" + |
| 74 |
"String.prototype.slice = function(sliceArg) {};" + |
| 75 |
"/** @type {number} */ String.prototype.length;" + |
| 76 |
"/** @constructor \n * @param {*} var_args \n @return {!Array} */" + |
| 77 |
"function Array(var_args) {}\n" + |
| 78 |
"/** @type {number} */ Array.prototype.length;\n" + |
| 79 |
"/**\n" + |
| 80 |
" * @param {...T} var_args\n" + |
| 81 |
" * @return {number} The new length of the array.\n" + |
| 82 |
" * @this {{length: number}|Array.<T>}\n" + |
| 83 |
" * @template T\n" + |
| 84 |
" * @modifies {this}\n" + |
| 85 |
" */\n" + |
| 86 |
"Array.prototype.push = function(var_args) {};" + |
| 87 |
"/** @constructor */\n" + |
| 88 |
"function Arguments() {}\n" + |
| 89 |
"/** @type {number} */\n" + |
| 90 |
"Arguments.prototype.length;\n" + |
| 91 |
"/** @type {!Arguments} */\n" + |
| 92 |
"var arguments;" + |
| 93 |
"" + ACTIVE_X_OBJECT_DEF; |
| 94 |
|
| 95 |
protected Compiler compiler; |
| 96 |
|
| 97 |
protected CompilerOptions getOptions() { |
| 98 |
CompilerOptions options = new CompilerOptions(); |
| 99 |
options.setLanguageIn(LanguageMode.ECMASCRIPT5); |
| 100 |
options.setWarningLevel( |
| 101 |
DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING); |
| 102 |
options.setWarningLevel( |
| 103 |
DiagnosticGroups.MISPLACED_TYPE_ANNOTATION, CheckLevel.WARNING); |
| 104 |
options.setWarningLevel( |
| 105 |
DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING); |
| 106 |
options.setCodingConvention(getCodingConvention()); |
| 107 |
return options; |
| 108 |
} |
| 109 |
|
| 110 |
protected CodingConvention getCodingConvention() { |
| 111 |
return new GoogleCodingConvention(); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
protected void setUp() throws Exception { |
| 116 |
compiler = new Compiler(); |
| 117 |
compiler.initOptions(getOptions()); |
| 118 |
registry = compiler.getTypeRegistry(); |
| 119 |
initTypes(); |
| 120 |
} |
| 121 |
} |