@thanhthbm/scene-editor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +169 -0
  2. package/dist/index.css +921 -0
  3. package/dist/index.js +14076 -0
  4. package/package.json +49 -0
  5. package/src/editor/css/main.css +1030 -0
  6. package/src/editor/js/Animation.js +618 -0
  7. package/src/editor/js/AnimationResizer.js +73 -0
  8. package/src/editor/js/Command.js +40 -0
  9. package/src/editor/js/Config.js +86 -0
  10. package/src/editor/js/Editor.js +1006 -0
  11. package/src/editor/js/EditorControls.js +489 -0
  12. package/src/editor/js/GLTFImportDialog.js +112 -0
  13. package/src/editor/js/History.js +321 -0
  14. package/src/editor/js/Loader.js +1162 -0
  15. package/src/editor/js/LoaderUtils.js +90 -0
  16. package/src/editor/js/Menubar.Add.js +559 -0
  17. package/src/editor/js/Menubar.Edit.js +155 -0
  18. package/src/editor/js/Menubar.File.js +585 -0
  19. package/src/editor/js/Menubar.Help.js +73 -0
  20. package/src/editor/js/Menubar.Render.js +858 -0
  21. package/src/editor/js/Menubar.Status.js +51 -0
  22. package/src/editor/js/Menubar.View.js +193 -0
  23. package/src/editor/js/Menubar.js +29 -0
  24. package/src/editor/js/Player.js +53 -0
  25. package/src/editor/js/Resizer.js +65 -0
  26. package/src/editor/js/Script.js +532 -0
  27. package/src/editor/js/Selector.js +129 -0
  28. package/src/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
  29. package/src/editor/js/Sidebar.Geometry.BufferGeometry.js +124 -0
  30. package/src/editor/js/Sidebar.Geometry.CapsuleGeometry.js +109 -0
  31. package/src/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
  32. package/src/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
  33. package/src/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
  34. package/src/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
  35. package/src/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
  36. package/src/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
  37. package/src/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
  38. package/src/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
  39. package/src/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
  40. package/src/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
  41. package/src/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
  42. package/src/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
  43. package/src/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
  44. package/src/editor/js/Sidebar.Geometry.TextGeometry.js +136 -0
  45. package/src/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
  46. package/src/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
  47. package/src/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
  48. package/src/editor/js/Sidebar.Geometry.js +471 -0
  49. package/src/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
  50. package/src/editor/js/Sidebar.Material.ColorProperty.js +87 -0
  51. package/src/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
  52. package/src/editor/js/Sidebar.Material.MapProperty.js +277 -0
  53. package/src/editor/js/Sidebar.Material.NumberProperty.js +60 -0
  54. package/src/editor/js/Sidebar.Material.Program.js +73 -0
  55. package/src/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
  56. package/src/editor/js/Sidebar.Material.js +751 -0
  57. package/src/editor/js/Sidebar.Object.js +892 -0
  58. package/src/editor/js/Sidebar.Project.App.js +218 -0
  59. package/src/editor/js/Sidebar.Project.Materials.js +82 -0
  60. package/src/editor/js/Sidebar.Project.Renderer.js +193 -0
  61. package/src/editor/js/Sidebar.Project.Resources.js +242 -0
  62. package/src/editor/js/Sidebar.Project.js +21 -0
  63. package/src/editor/js/Sidebar.Properties.js +73 -0
  64. package/src/editor/js/Sidebar.Scene.js +643 -0
  65. package/src/editor/js/Sidebar.Script.js +129 -0
  66. package/src/editor/js/Sidebar.Settings.History.js +146 -0
  67. package/src/editor/js/Sidebar.Settings.Shortcuts.js +198 -0
  68. package/src/editor/js/Sidebar.Settings.js +58 -0
  69. package/src/editor/js/Sidebar.js +41 -0
  70. package/src/editor/js/Storage.js +98 -0
  71. package/src/editor/js/Strings.js +2718 -0
  72. package/src/editor/js/TextureParametersDialog.js +293 -0
  73. package/src/editor/js/Toolbar.js +75 -0
  74. package/src/editor/js/Viewport.Controls.js +98 -0
  75. package/src/editor/js/Viewport.Info.js +144 -0
  76. package/src/editor/js/Viewport.Pathtracer.js +27 -0
  77. package/src/editor/js/Viewport.ViewHelper.js +41 -0
  78. package/src/editor/js/Viewport.XR.js +7 -0
  79. package/src/editor/js/Viewport.js +982 -0
  80. package/src/editor/js/commands/AddObjectCommand.js +68 -0
  81. package/src/editor/js/commands/AddScriptCommand.js +75 -0
  82. package/src/editor/js/commands/Commands.js +24 -0
  83. package/src/editor/js/commands/MoveObjectCommand.js +117 -0
  84. package/src/editor/js/commands/MultiCmdsCommand.js +85 -0
  85. package/src/editor/js/commands/RemoveObjectCommand.js +88 -0
  86. package/src/editor/js/commands/RemoveScriptCommand.js +81 -0
  87. package/src/editor/js/commands/SetColorCommand.js +73 -0
  88. package/src/editor/js/commands/SetGeometryCommand.js +86 -0
  89. package/src/editor/js/commands/SetGeometryValueCommand.js +70 -0
  90. package/src/editor/js/commands/SetMaterialColorCommand.js +87 -0
  91. package/src/editor/js/commands/SetMaterialCommand.js +80 -0
  92. package/src/editor/js/commands/SetMaterialMapCommand.js +144 -0
  93. package/src/editor/js/commands/SetMaterialRangeCommand.js +92 -0
  94. package/src/editor/js/commands/SetMaterialValueCommand.js +91 -0
  95. package/src/editor/js/commands/SetMaterialVectorCommand.js +88 -0
  96. package/src/editor/js/commands/SetPositionCommand.js +84 -0
  97. package/src/editor/js/commands/SetRotationCommand.js +84 -0
  98. package/src/editor/js/commands/SetScaleCommand.js +84 -0
  99. package/src/editor/js/commands/SetSceneCommand.js +104 -0
  100. package/src/editor/js/commands/SetScriptValueCommand.js +80 -0
  101. package/src/editor/js/commands/SetShadowValueCommand.js +73 -0
  102. package/src/editor/js/commands/SetTextureParametersCommand.js +143 -0
  103. package/src/editor/js/commands/SetUuidCommand.js +70 -0
  104. package/src/editor/js/commands/SetValueCommand.js +75 -0
  105. package/src/editor/js/libs/acorn/acorn.js +3236 -0
  106. package/src/editor/js/libs/acorn/acorn_loose.js +1299 -0
  107. package/src/editor/js/libs/acorn/walk.js +344 -0
  108. package/src/editor/js/libs/app/index.html +51 -0
  109. package/src/editor/js/libs/app.js +14 -0
  110. package/src/editor/js/libs/codemirror/addon/dialog.css +32 -0
  111. package/src/editor/js/libs/codemirror/addon/dialog.js +163 -0
  112. package/src/editor/js/libs/codemirror/addon/show-hint.css +36 -0
  113. package/src/editor/js/libs/codemirror/addon/show-hint.js +529 -0
  114. package/src/editor/js/libs/codemirror/addon/tern.css +87 -0
  115. package/src/editor/js/libs/codemirror/addon/tern.js +750 -0
  116. package/src/editor/js/libs/codemirror/codemirror.css +344 -0
  117. package/src/editor/js/libs/codemirror/codemirror.js +9849 -0
  118. package/src/editor/js/libs/codemirror/mode/glsl.js +233 -0
  119. package/src/editor/js/libs/codemirror/mode/javascript.js +959 -0
  120. package/src/editor/js/libs/codemirror/theme/monokai.css +41 -0
  121. package/src/editor/js/libs/esprima.js +6401 -0
  122. package/src/editor/js/libs/jsonlint.js +453 -0
  123. package/src/editor/js/libs/signals.min.js +14 -0
  124. package/src/editor/js/libs/tern-threejs/build-defs.js +233 -0
  125. package/src/editor/js/libs/ternjs/comment.js +87 -0
  126. package/src/editor/js/libs/ternjs/def.js +588 -0
  127. package/src/editor/js/libs/ternjs/doc_comment.js +401 -0
  128. package/src/editor/js/libs/ternjs/infer.js +1635 -0
  129. package/src/editor/js/libs/ternjs/polyfill.js +80 -0
  130. package/src/editor/js/libs/ternjs/signal.js +26 -0
  131. package/src/editor/js/libs/ternjs/tern.js +993 -0
  132. package/src/editor/js/libs/ui.js +1305 -0
  133. package/src/editor/js/libs/ui.three.js +946 -0
  134. package/src/events.js +273 -0
  135. package/src/index.js +284 -0
  136. package/src/presets/machines.js +239 -0
@@ -0,0 +1,401 @@
1
+ // Parses comments above variable declarations, function declarations,
2
+ // and object properties as docstrings and JSDoc-style type
3
+ // annotations.
4
+
5
+ (function(mod) {
6
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
7
+ return mod(require("../lib/infer"), require("../lib/tern"), require("../lib/comment"),
8
+ require("acorn"), require("acorn/dist/walk"));
9
+ if (typeof define == "function" && define.amd) // AMD
10
+ return define(["../lib/infer", "../lib/tern", "../lib/comment", "acorn/dist/acorn", "acorn/dist/walk"], mod);
11
+ mod(tern, tern, tern.comment, acorn, acorn.walk);
12
+ })(function(infer, tern, comment, acorn, walk) {
13
+ "use strict";
14
+
15
+ var WG_MADEUP = 1, WG_STRONG = 101;
16
+
17
+ tern.registerPlugin("doc_comment", function(server, options) {
18
+ server.jsdocTypedefs = Object.create(null);
19
+ server.on("reset", function() {
20
+ server.jsdocTypedefs = Object.create(null);
21
+ });
22
+ server._docComment = {
23
+ weight: options && options.strong ? WG_STRONG : undefined,
24
+ fullDocs: options && options.fullDocs
25
+ };
26
+
27
+ return {
28
+ passes: {
29
+ postParse: postParse,
30
+ postInfer: postInfer,
31
+ postLoadDef: postLoadDef
32
+ }
33
+ };
34
+ });
35
+
36
+ function postParse(ast, text) {
37
+ function attachComments(node) { comment.ensureCommentsBefore(text, node); }
38
+
39
+ walk.simple(ast, {
40
+ VariableDeclaration: attachComments,
41
+ FunctionDeclaration: attachComments,
42
+ AssignmentExpression: function(node) {
43
+ if (node.operator == "=") attachComments(node);
44
+ },
45
+ ObjectExpression: function(node) {
46
+ for (var i = 0; i < node.properties.length; ++i)
47
+ attachComments(node.properties[i]);
48
+ },
49
+ CallExpression: function(node) {
50
+ if (isDefinePropertyCall(node)) attachComments(node);
51
+ }
52
+ });
53
+ }
54
+
55
+ function isDefinePropertyCall(node) {
56
+ return node.callee.type == "MemberExpression" &&
57
+ node.callee.object.name == "Object" &&
58
+ node.callee.property.name == "defineProperty" &&
59
+ node.arguments.length >= 3 &&
60
+ typeof node.arguments[1].value == "string";
61
+ }
62
+
63
+ function postInfer(ast, scope) {
64
+ jsdocParseTypedefs(ast.sourceFile.text, scope);
65
+
66
+ walk.simple(ast, {
67
+ VariableDeclaration: function(node, scope) {
68
+ if (node.commentsBefore)
69
+ interpretComments(node, node.commentsBefore, scope,
70
+ scope.getProp(node.declarations[0].id.name));
71
+ },
72
+ FunctionDeclaration: function(node, scope) {
73
+ if (node.commentsBefore)
74
+ interpretComments(node, node.commentsBefore, scope,
75
+ scope.getProp(node.id.name),
76
+ node.body.scope.fnType);
77
+ },
78
+ AssignmentExpression: function(node, scope) {
79
+ if (node.commentsBefore)
80
+ interpretComments(node, node.commentsBefore, scope,
81
+ infer.expressionType({node: node.left, state: scope}));
82
+ },
83
+ ObjectExpression: function(node, scope) {
84
+ for (var i = 0; i < node.properties.length; ++i) {
85
+ var prop = node.properties[i];
86
+ if (prop.commentsBefore)
87
+ interpretComments(prop, prop.commentsBefore, scope,
88
+ node.objType.getProp(prop.key.name));
89
+ }
90
+ },
91
+ CallExpression: function(node, scope) {
92
+ if (node.commentsBefore && isDefinePropertyCall(node)) {
93
+ var type = infer.expressionType({node: node.arguments[0], state: scope}).getObjType();
94
+ if (type && type instanceof infer.Obj) {
95
+ var prop = type.props[node.arguments[1].value];
96
+ if (prop) interpretComments(node, node.commentsBefore, scope, prop);
97
+ }
98
+ }
99
+ }
100
+ }, infer.searchVisitor, scope);
101
+ }
102
+
103
+ function postLoadDef(data) {
104
+ var defs = data["!typedef"];
105
+ var cx = infer.cx(), orig = data["!name"];
106
+ if (defs) for (var name in defs)
107
+ cx.parent.jsdocTypedefs[name] =
108
+ maybeInstance(infer.def.parse(defs[name], orig, name), name);
109
+ }
110
+
111
+ // COMMENT INTERPRETATION
112
+
113
+ function interpretComments(node, comments, scope, aval, type) {
114
+ jsdocInterpretComments(node, scope, aval, comments);
115
+ var cx = infer.cx();
116
+
117
+ if (!type && aval instanceof infer.AVal && aval.types.length) {
118
+ type = aval.types[aval.types.length - 1];
119
+ if (!(type instanceof infer.Obj) || type.origin != cx.curOrigin || type.doc)
120
+ type = null;
121
+ }
122
+
123
+ var result = comments[comments.length - 1];
124
+ if (cx.parent._docComment.fullDocs) {
125
+ result = result.trim().replace(/\n[ \t]*\* ?/g, "\n");
126
+ } else {
127
+ var dot = result.search(/\.\s/);
128
+ if (dot > 5) result = result.slice(0, dot + 1);
129
+ result = result.trim().replace(/\s*\n\s*\*\s*|\s{1,}/g, " ");
130
+ }
131
+ result = result.replace(/^\s*\*+\s*/, "");
132
+
133
+ if (aval instanceof infer.AVal) aval.doc = result;
134
+ if (type) type.doc = result;
135
+ }
136
+
137
+ // Parses a subset of JSDoc-style comments in order to include the
138
+ // explicitly defined types in the analysis.
139
+
140
+ function skipSpace(str, pos) {
141
+ while (/\s/.test(str.charAt(pos))) ++pos;
142
+ return pos;
143
+ }
144
+
145
+ function isIdentifier(string) {
146
+ if (!acorn.isIdentifierStart(string.charCodeAt(0))) return false;
147
+ for (var i = 1; i < string.length; i++)
148
+ if (!acorn.isIdentifierChar(string.charCodeAt(i))) return false;
149
+ return true;
150
+ }
151
+
152
+ function parseLabelList(scope, str, pos, close) {
153
+ var labels = [], types = [], madeUp = false;
154
+ for (var first = true; ; first = false) {
155
+ pos = skipSpace(str, pos);
156
+ if (first && str.charAt(pos) == close) break;
157
+ var colon = str.indexOf(":", pos);
158
+ if (colon < 0) return null;
159
+ var label = str.slice(pos, colon);
160
+ if (!isIdentifier(label)) return null;
161
+ labels.push(label);
162
+ pos = colon + 1;
163
+ var type = parseType(scope, str, pos);
164
+ if (!type) return null;
165
+ pos = type.end;
166
+ madeUp = madeUp || type.madeUp;
167
+ types.push(type.type);
168
+ pos = skipSpace(str, pos);
169
+ var next = str.charAt(pos);
170
+ ++pos;
171
+ if (next == close) break;
172
+ if (next != ",") return null;
173
+ }
174
+ return {labels: labels, types: types, end: pos, madeUp: madeUp};
175
+ }
176
+
177
+ function parseType(scope, str, pos) {
178
+ var type, union = false, madeUp = false;
179
+ for (;;) {
180
+ var inner = parseTypeInner(scope, str, pos);
181
+ if (!inner) return null;
182
+ madeUp = madeUp || inner.madeUp;
183
+ if (union) inner.type.propagate(union);
184
+ else type = inner.type;
185
+ pos = skipSpace(str, inner.end);
186
+ if (str.charAt(pos) != "|") break;
187
+ pos++;
188
+ if (!union) {
189
+ union = new infer.AVal;
190
+ type.propagate(union);
191
+ type = union;
192
+ }
193
+ }
194
+ var isOptional = false;
195
+ if (str.charAt(pos) == "=") {
196
+ ++pos;
197
+ isOptional = true;
198
+ }
199
+ return {type: type, end: pos, isOptional: isOptional, madeUp: madeUp};
200
+ }
201
+
202
+ function parseTypeInner(scope, str, pos) {
203
+ pos = skipSpace(str, pos);
204
+ var type, madeUp = false;
205
+
206
+ if (str.indexOf("function(", pos) == pos) {
207
+ var args = parseLabelList(scope, str, pos + 9, ")"), ret = infer.ANull;
208
+ if (!args) return null;
209
+ pos = skipSpace(str, args.end);
210
+ if (str.charAt(pos) == ":") {
211
+ ++pos;
212
+ var retType = parseType(scope, str, pos + 1);
213
+ if (!retType) return null;
214
+ pos = retType.end;
215
+ ret = retType.type;
216
+ madeUp = retType.madeUp;
217
+ }
218
+ type = new infer.Fn(null, infer.ANull, args.types, args.labels, ret);
219
+ } else if (str.charAt(pos) == "[") {
220
+ var inner = parseType(scope, str, pos + 1);
221
+ if (!inner) return null;
222
+ pos = skipSpace(str, inner.end);
223
+ madeUp = inner.madeUp;
224
+ if (str.charAt(pos) != "]") return null;
225
+ ++pos;
226
+ type = new infer.Arr(inner.type);
227
+ } else if (str.charAt(pos) == "{") {
228
+ var fields = parseLabelList(scope, str, pos + 1, "}");
229
+ if (!fields) return null;
230
+ type = new infer.Obj(true);
231
+ for (var i = 0; i < fields.types.length; ++i) {
232
+ var field = type.defProp(fields.labels[i]);
233
+ field.initializer = true;
234
+ fields.types[i].propagate(field);
235
+ }
236
+ pos = fields.end;
237
+ madeUp = fields.madeUp;
238
+ } else if (str.charAt(pos) == "(") {
239
+ var inner = parseType(scope, str, pos + 1);
240
+ if (!inner) return null;
241
+ pos = skipSpace(str, inner.end);
242
+ if (str.charAt(pos) != ")") return null;
243
+ ++pos;
244
+ type = inner.type;
245
+ } else {
246
+ var start = pos;
247
+ if (!acorn.isIdentifierStart(str.charCodeAt(pos))) return null;
248
+ while (acorn.isIdentifierChar(str.charCodeAt(pos))) ++pos;
249
+ if (start == pos) return null;
250
+ var word = str.slice(start, pos);
251
+ if (/^(number|integer)$/i.test(word)) type = infer.cx().num;
252
+ else if (/^bool(ean)?$/i.test(word)) type = infer.cx().bool;
253
+ else if (/^string$/i.test(word)) type = infer.cx().str;
254
+ else if (/^(null|undefined)$/i.test(word)) type = infer.ANull;
255
+ else if (/^array$/i.test(word)) {
256
+ var inner = null;
257
+ if (str.charAt(pos) == "." && str.charAt(pos + 1) == "<") {
258
+ var inAngles = parseType(scope, str, pos + 2);
259
+ if (!inAngles) return null;
260
+ pos = skipSpace(str, inAngles.end);
261
+ madeUp = inAngles.madeUp;
262
+ if (str.charAt(pos++) != ">") return null;
263
+ inner = inAngles.type;
264
+ }
265
+ type = new infer.Arr(inner);
266
+ } else if (/^object$/i.test(word)) {
267
+ type = new infer.Obj(true);
268
+ if (str.charAt(pos) == "." && str.charAt(pos + 1) == "<") {
269
+ var key = parseType(scope, str, pos + 2);
270
+ if (!key) return null;
271
+ pos = skipSpace(str, key.end);
272
+ if (str.charAt(pos++) != ",") return null;
273
+ var val = parseType(scope, str, pos);
274
+ if (!val) return null;
275
+ pos = skipSpace(str, val.end);
276
+ madeUp = key.madeUp || val.madeUp;
277
+ if (str.charAt(pos++) != ">") return null;
278
+ val.type.propagate(type.defProp("<i>"));
279
+ }
280
+ } else {
281
+ while (str.charCodeAt(pos) == 46 ||
282
+ acorn.isIdentifierChar(str.charCodeAt(pos))) ++pos;
283
+ var path = str.slice(start, pos);
284
+ var cx = infer.cx(), defs = cx.parent && cx.parent.jsdocTypedefs, found;
285
+ if (defs && (path in defs)) {
286
+ type = defs[path];
287
+ } else if (found = infer.def.parsePath(path, scope).getObjType()) {
288
+ type = maybeInstance(found, path);
289
+ } else {
290
+ if (!cx.jsdocPlaceholders) cx.jsdocPlaceholders = Object.create(null);
291
+ if (!(path in cx.jsdocPlaceholders))
292
+ type = cx.jsdocPlaceholders[path] = new infer.Obj(null, path);
293
+ else
294
+ type = cx.jsdocPlaceholders[path];
295
+ madeUp = true;
296
+ }
297
+ }
298
+ }
299
+
300
+ return {type: type, end: pos, madeUp: madeUp};
301
+ }
302
+
303
+ function maybeInstance(type, path) {
304
+ if (type instanceof infer.Fn && /^[A-Z]/.test(path)) {
305
+ var proto = type.getProp("prototype").getObjType();
306
+ if (proto instanceof infer.Obj) return infer.getInstance(proto);
307
+ }
308
+ return type;
309
+ }
310
+
311
+ function parseTypeOuter(scope, str, pos) {
312
+ pos = skipSpace(str, pos || 0);
313
+ if (str.charAt(pos) != "{") return null;
314
+ var result = parseType(scope, str, pos + 1);
315
+ if (!result) return null;
316
+ var end = skipSpace(str, result.end);
317
+ if (str.charAt(end) != "}") return null;
318
+ result.end = end + 1;
319
+ return result;
320
+ }
321
+
322
+ function jsdocInterpretComments(node, scope, aval, comments) {
323
+ var type, args, ret, foundOne, self, parsed;
324
+
325
+ for (var i = 0; i < comments.length; ++i) {
326
+ var comment = comments[i];
327
+ var decl = /(?:\n|\$|\*)\s*@(type|param|arg(?:ument)?|returns?|this)\s+(.*)/g, m;
328
+ while (m = decl.exec(comment)) {
329
+ if (m[1] == "this" && (parsed = parseType(scope, m[2], 0))) {
330
+ self = parsed;
331
+ foundOne = true;
332
+ continue;
333
+ }
334
+
335
+ if (!(parsed = parseTypeOuter(scope, m[2]))) continue;
336
+ foundOne = true;
337
+
338
+ switch(m[1]) {
339
+ case "returns": case "return":
340
+ ret = parsed; break;
341
+ case "type":
342
+ type = parsed; break;
343
+ case "param": case "arg": case "argument":
344
+ var name = m[2].slice(parsed.end).match(/^\s*(\[?)\s*([^\]\s=]+)\s*(?:=[^\]]+\s*)?(\]?).*/);
345
+ if (!name) continue;
346
+ var argname = name[2] + (parsed.isOptional || (name[1] === '[' && name[3] === ']') ? "?" : "");
347
+ (args || (args = Object.create(null)))[argname] = parsed;
348
+ break;
349
+ }
350
+ }
351
+ }
352
+
353
+ if (foundOne) applyType(type, self, args, ret, node, aval);
354
+ };
355
+
356
+ function jsdocParseTypedefs(text, scope) {
357
+ var cx = infer.cx();
358
+
359
+ var re = /\s@typedef\s+(.*)/g, m;
360
+ while (m = re.exec(text)) {
361
+ var parsed = parseTypeOuter(scope, m[1]);
362
+ var name = parsed && m[1].slice(parsed.end).match(/^\s*(\S+)/);
363
+ if (name)
364
+ cx.parent.jsdocTypedefs[name[1]] = parsed.type;
365
+ }
366
+ }
367
+
368
+ function propagateWithWeight(type, target) {
369
+ var weight = infer.cx().parent._docComment.weight;
370
+ type.type.propagate(target, weight || (type.madeUp ? WG_MADEUP : undefined));
371
+ }
372
+
373
+ function applyType(type, self, args, ret, node, aval) {
374
+ var fn;
375
+ if (node.type == "VariableDeclaration") {
376
+ var decl = node.declarations[0];
377
+ if (decl.init && decl.init.type == "FunctionExpression") fn = decl.init.body.scope.fnType;
378
+ } else if (node.type == "FunctionDeclaration") {
379
+ fn = node.body.scope.fnType;
380
+ } else if (node.type == "AssignmentExpression") {
381
+ if (node.right.type == "FunctionExpression")
382
+ fn = node.right.body.scope.fnType;
383
+ } else if (node.type == "CallExpression") {
384
+ } else { // An object property
385
+ if (node.value.type == "FunctionExpression") fn = node.value.body.scope.fnType;
386
+ }
387
+
388
+ if (fn && (args || ret || self)) {
389
+ if (args) for (var i = 0; i < fn.argNames.length; ++i) {
390
+ var name = fn.argNames[i], known = args[name];
391
+ if (!known && (known = args[name + "?"]))
392
+ fn.argNames[i] += "?";
393
+ if (known) propagateWithWeight(known, fn.args[i]);
394
+ }
395
+ if (ret) propagateWithWeight(ret, fn.retval);
396
+ if (self) propagateWithWeight(self, fn.self);
397
+ } else if (type) {
398
+ propagateWithWeight(type, aval);
399
+ }
400
+ };
401
+ });