spoint 0.1.0 → 0.1.11
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.
- package/README.md +134 -209
- package/SKILL.md +95 -0
- package/apps/environment/index.js +200 -1
- package/apps/environment/models/decorative/.gitkeep +0 -0
- package/apps/environment/models/hazards/.gitkeep +0 -0
- package/apps/environment/models/interactive/.gitkeep +0 -0
- package/apps/environment/models/structures/.gitkeep +0 -0
- package/apps/environment/smartObjects.js +114 -0
- package/apps/interactable/index.js +155 -0
- package/apps/physics-crate/index.js +15 -9
- package/apps/power-crate/index.js +18 -12
- package/apps/tps-game/$GDUPI.vrm +0 -0
- package/apps/tps-game/Cleetus.vrm +0 -0
- package/apps/tps-game/index.js +185 -27
- package/apps/world/index.js +68 -22
- package/bin/create-app.js +337 -0
- package/client/ARControls.js +301 -0
- package/client/LoadingManager.js +117 -0
- package/client/MobileControls.js +1122 -0
- package/client/anim-lib.glb +0 -0
- package/client/animation.js +306 -0
- package/client/app.js +1341 -65
- package/client/camera.js +191 -33
- package/client/createLoadingScreen.js +69 -0
- package/client/editor/bridge.js +113 -0
- package/client/editor/css/main.css +794 -0
- package/client/editor/images/rotate.svg +4 -0
- package/client/editor/images/scale.svg +4 -0
- package/client/editor/images/translate.svg +4 -0
- package/client/editor/index.html +103 -0
- package/client/editor/js/Command.js +41 -0
- package/client/editor/js/Config.js +81 -0
- package/client/editor/js/Editor.js +785 -0
- package/client/editor/js/EditorControls.js +438 -0
- package/client/editor/js/History.js +321 -0
- package/client/editor/js/Loader.js +987 -0
- package/client/editor/js/LoaderUtils.js +90 -0
- package/client/editor/js/Menubar.Add.js +510 -0
- package/client/editor/js/Menubar.Edit.js +145 -0
- package/client/editor/js/Menubar.File.js +466 -0
- package/client/editor/js/Menubar.Help.js +73 -0
- package/client/editor/js/Menubar.Status.js +51 -0
- package/client/editor/js/Menubar.View.js +183 -0
- package/client/editor/js/Menubar.js +27 -0
- package/client/editor/js/Player.js +53 -0
- package/client/editor/js/Resizer.js +58 -0
- package/client/editor/js/Script.js +503 -0
- package/client/editor/js/Selector.js +102 -0
- package/client/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.BufferGeometry.js +115 -0
- package/client/editor/js/Sidebar.Geometry.CapsuleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/client/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/client/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/client/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/client/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/client/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/client/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/client/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/client/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/client/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/client/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/client/editor/js/Sidebar.Geometry.js +332 -0
- package/client/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/client/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/client/editor/js/Sidebar.Material.MapProperty.js +249 -0
- package/client/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/client/editor/js/Sidebar.Material.Program.js +73 -0
- package/client/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/client/editor/js/Sidebar.Material.js +751 -0
- package/client/editor/js/Sidebar.Object.Animation.js +102 -0
- package/client/editor/js/Sidebar.Object.js +898 -0
- package/client/editor/js/Sidebar.Project.App.js +165 -0
- package/client/editor/js/Sidebar.Project.Image.js +225 -0
- package/client/editor/js/Sidebar.Project.Materials.js +82 -0
- package/client/editor/js/Sidebar.Project.Renderer.js +144 -0
- package/client/editor/js/Sidebar.Project.Video.js +242 -0
- package/client/editor/js/Sidebar.Project.js +31 -0
- package/client/editor/js/Sidebar.Properties.js +73 -0
- package/client/editor/js/Sidebar.Scene.js +585 -0
- package/client/editor/js/Sidebar.Script.js +129 -0
- package/client/editor/js/Sidebar.Settings.History.js +146 -0
- package/client/editor/js/Sidebar.Settings.Shortcuts.js +175 -0
- package/client/editor/js/Sidebar.Settings.js +60 -0
- package/client/editor/js/Sidebar.js +41 -0
- package/client/editor/js/Storage.js +98 -0
- package/client/editor/js/Strings.js +2028 -0
- package/client/editor/js/Toolbar.js +84 -0
- package/client/editor/js/Viewport.Controls.js +92 -0
- package/client/editor/js/Viewport.Info.js +136 -0
- package/client/editor/js/Viewport.Pathtracer.js +91 -0
- package/client/editor/js/Viewport.ViewHelper.js +39 -0
- package/client/editor/js/Viewport.XR.js +222 -0
- package/client/editor/js/Viewport.js +900 -0
- package/client/editor/js/commands/AddObjectCommand.js +68 -0
- package/client/editor/js/commands/AddScriptCommand.js +75 -0
- package/client/editor/js/commands/Commands.js +23 -0
- package/client/editor/js/commands/MoveObjectCommand.js +111 -0
- package/client/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/client/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/client/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/client/editor/js/commands/SetColorCommand.js +73 -0
- package/client/editor/js/commands/SetGeometryCommand.js +87 -0
- package/client/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/client/editor/js/commands/SetMaterialColorCommand.js +86 -0
- package/client/editor/js/commands/SetMaterialCommand.js +79 -0
- package/client/editor/js/commands/SetMaterialMapCommand.js +143 -0
- package/client/editor/js/commands/SetMaterialRangeCommand.js +91 -0
- package/client/editor/js/commands/SetMaterialValueCommand.js +90 -0
- package/client/editor/js/commands/SetMaterialVectorCommand.js +79 -0
- package/client/editor/js/commands/SetPositionCommand.js +84 -0
- package/client/editor/js/commands/SetRotationCommand.js +84 -0
- package/client/editor/js/commands/SetScaleCommand.js +84 -0
- package/client/editor/js/commands/SetSceneCommand.js +103 -0
- package/client/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/client/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/client/editor/js/commands/SetUuidCommand.js +70 -0
- package/client/editor/js/commands/SetValueCommand.js +75 -0
- package/client/editor/js/libs/acorn/acorn.js +3236 -0
- package/client/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/client/editor/js/libs/acorn/walk.js +344 -0
- package/client/editor/js/libs/app/index.html +57 -0
- package/client/editor/js/libs/app.js +251 -0
- package/client/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/client/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/client/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/client/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/client/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/client/editor/js/libs/codemirror/codemirror.css +344 -0
- package/client/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/client/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/client/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/client/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/client/editor/js/libs/esprima.js +6401 -0
- package/client/editor/js/libs/jsonlint.js +453 -0
- package/client/editor/js/libs/signals.min.js +14 -0
- package/client/editor/js/libs/tern-threejs/threejs.js +5031 -0
- package/client/editor/js/libs/ternjs/comment.js +87 -0
- package/client/editor/js/libs/ternjs/def.js +588 -0
- package/client/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/client/editor/js/libs/ternjs/infer.js +1635 -0
- package/client/editor/js/libs/ternjs/polyfill.js +80 -0
- package/client/editor/js/libs/ternjs/signal.js +26 -0
- package/client/editor/js/libs/ternjs/tern.js +993 -0
- package/client/editor/js/libs/ui.js +1346 -0
- package/client/editor/js/libs/ui.three.js +855 -0
- package/client/facial-animation.js +455 -0
- package/client/index.html +7 -4
- package/client/loading.css +147 -0
- package/client/loading.html +25 -0
- package/client/style.css +251 -0
- package/package.json +7 -3
- package/server.js +9 -1
- package/src/apps/AppContext.js +1 -1
- package/src/apps/AppLoader.js +50 -37
- package/src/apps/AppRuntime.js +32 -8
- package/src/client/InputHandler.js +233 -0
- package/src/client/JitterBuffer.js +207 -0
- package/src/client/KalmanFilter.js +125 -0
- package/src/client/MessageHandler.js +101 -0
- package/src/client/PhysicsNetworkClient.js +141 -68
- package/src/client/ReconnectManager.js +62 -0
- package/src/client/SmoothInterpolation.js +127 -0
- package/src/client/SnapshotProcessor.js +144 -0
- package/src/connection/ConnectionManager.js +21 -3
- package/src/connection/SessionStore.js +13 -3
- package/src/index.client.js +4 -6
- package/src/netcode/EventLog.js +29 -15
- package/src/netcode/LagCompensator.js +25 -26
- package/src/netcode/NetworkState.js +4 -1
- package/src/netcode/PhysicsIntegration.js +20 -6
- package/src/netcode/PlayerManager.js +10 -2
- package/src/netcode/SnapshotEncoder.js +66 -19
- package/src/netcode/TickSystem.js +13 -4
- package/src/physics/World.js +66 -13
- package/src/protocol/msgpack.js +90 -63
- package/src/sdk/ReloadHandlers.js +12 -2
- package/src/sdk/ReloadManager.js +5 -0
- package/src/sdk/ServerHandlers.js +50 -11
- package/src/sdk/StaticHandler.js +22 -6
- package/src/sdk/TickHandler.js +101 -34
- package/src/sdk/scaffold.js +31 -0
- package/src/sdk/server.js +59 -33
- package/src/shared/movement.js +2 -1
- package/src/spatial/Octree.js +5 -0
- package/apps/interactive-door/index.js +0 -33
- package/apps/patrol-npc/index.js +0 -37
- package/src/connection/QualityMonitor.js +0 -46
- package/src/debug/StateInspector.js +0 -42
- package/src/index.js +0 -1
- package/src/index.server.js +0 -27
- package/src/protocol/Codec.js +0 -60
- package/src/protocol/SequenceTracker.js +0 -71
- package/src/sdk/ClientMessageHandler.js +0 -80
- package/src/sdk/client.js +0 -122
- package/world/kaira.glb +0 -0
- package/world/schwust.glb +0 -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
|
+
});
|