@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.
- package/README.md +169 -0
- package/dist/index.css +921 -0
- package/dist/index.js +14076 -0
- package/package.json +49 -0
- package/src/editor/css/main.css +1030 -0
- package/src/editor/js/Animation.js +618 -0
- package/src/editor/js/AnimationResizer.js +73 -0
- package/src/editor/js/Command.js +40 -0
- package/src/editor/js/Config.js +86 -0
- package/src/editor/js/Editor.js +1006 -0
- package/src/editor/js/EditorControls.js +489 -0
- package/src/editor/js/GLTFImportDialog.js +112 -0
- package/src/editor/js/History.js +321 -0
- package/src/editor/js/Loader.js +1162 -0
- package/src/editor/js/LoaderUtils.js +90 -0
- package/src/editor/js/Menubar.Add.js +559 -0
- package/src/editor/js/Menubar.Edit.js +155 -0
- package/src/editor/js/Menubar.File.js +585 -0
- package/src/editor/js/Menubar.Help.js +73 -0
- package/src/editor/js/Menubar.Render.js +858 -0
- package/src/editor/js/Menubar.Status.js +51 -0
- package/src/editor/js/Menubar.View.js +193 -0
- package/src/editor/js/Menubar.js +29 -0
- package/src/editor/js/Player.js +53 -0
- package/src/editor/js/Resizer.js +65 -0
- package/src/editor/js/Script.js +532 -0
- package/src/editor/js/Selector.js +129 -0
- package/src/editor/js/Sidebar.Geometry.BoxGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.BufferGeometry.js +124 -0
- package/src/editor/js/Sidebar.Geometry.CapsuleGeometry.js +109 -0
- package/src/editor/js/Sidebar.Geometry.CircleGeometry.js +97 -0
- package/src/editor/js/Sidebar.Geometry.CylinderGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.DodecahedronGeometry.js +73 -0
- package/src/editor/js/Sidebar.Geometry.ExtrudeGeometry.js +196 -0
- package/src/editor/js/Sidebar.Geometry.IcosahedronGeometry.js +73 -0
- package/src/editor/js/Sidebar.Geometry.LatheGeometry.js +98 -0
- package/src/editor/js/Sidebar.Geometry.Modifiers.js +73 -0
- package/src/editor/js/Sidebar.Geometry.OctahedronGeometry.js +74 -0
- package/src/editor/js/Sidebar.Geometry.PlaneGeometry.js +97 -0
- package/src/editor/js/Sidebar.Geometry.RingGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.ShapeGeometry.js +76 -0
- package/src/editor/js/Sidebar.Geometry.SphereGeometry.js +133 -0
- package/src/editor/js/Sidebar.Geometry.TetrahedronGeometry.js +74 -0
- package/src/editor/js/Sidebar.Geometry.TextGeometry.js +136 -0
- package/src/editor/js/Sidebar.Geometry.TorusGeometry.js +109 -0
- package/src/editor/js/Sidebar.Geometry.TorusKnotGeometry.js +121 -0
- package/src/editor/js/Sidebar.Geometry.TubeGeometry.js +135 -0
- package/src/editor/js/Sidebar.Geometry.js +471 -0
- package/src/editor/js/Sidebar.Material.BooleanProperty.js +60 -0
- package/src/editor/js/Sidebar.Material.ColorProperty.js +87 -0
- package/src/editor/js/Sidebar.Material.ConstantProperty.js +62 -0
- package/src/editor/js/Sidebar.Material.MapProperty.js +277 -0
- package/src/editor/js/Sidebar.Material.NumberProperty.js +60 -0
- package/src/editor/js/Sidebar.Material.Program.js +73 -0
- package/src/editor/js/Sidebar.Material.RangeValueProperty.js +63 -0
- package/src/editor/js/Sidebar.Material.js +751 -0
- package/src/editor/js/Sidebar.Object.js +892 -0
- package/src/editor/js/Sidebar.Project.App.js +218 -0
- package/src/editor/js/Sidebar.Project.Materials.js +82 -0
- package/src/editor/js/Sidebar.Project.Renderer.js +193 -0
- package/src/editor/js/Sidebar.Project.Resources.js +242 -0
- package/src/editor/js/Sidebar.Project.js +21 -0
- package/src/editor/js/Sidebar.Properties.js +73 -0
- package/src/editor/js/Sidebar.Scene.js +643 -0
- package/src/editor/js/Sidebar.Script.js +129 -0
- package/src/editor/js/Sidebar.Settings.History.js +146 -0
- package/src/editor/js/Sidebar.Settings.Shortcuts.js +198 -0
- package/src/editor/js/Sidebar.Settings.js +58 -0
- package/src/editor/js/Sidebar.js +41 -0
- package/src/editor/js/Storage.js +98 -0
- package/src/editor/js/Strings.js +2718 -0
- package/src/editor/js/TextureParametersDialog.js +293 -0
- package/src/editor/js/Toolbar.js +75 -0
- package/src/editor/js/Viewport.Controls.js +98 -0
- package/src/editor/js/Viewport.Info.js +144 -0
- package/src/editor/js/Viewport.Pathtracer.js +27 -0
- package/src/editor/js/Viewport.ViewHelper.js +41 -0
- package/src/editor/js/Viewport.XR.js +7 -0
- package/src/editor/js/Viewport.js +982 -0
- package/src/editor/js/commands/AddObjectCommand.js +68 -0
- package/src/editor/js/commands/AddScriptCommand.js +75 -0
- package/src/editor/js/commands/Commands.js +24 -0
- package/src/editor/js/commands/MoveObjectCommand.js +117 -0
- package/src/editor/js/commands/MultiCmdsCommand.js +85 -0
- package/src/editor/js/commands/RemoveObjectCommand.js +88 -0
- package/src/editor/js/commands/RemoveScriptCommand.js +81 -0
- package/src/editor/js/commands/SetColorCommand.js +73 -0
- package/src/editor/js/commands/SetGeometryCommand.js +86 -0
- package/src/editor/js/commands/SetGeometryValueCommand.js +70 -0
- package/src/editor/js/commands/SetMaterialColorCommand.js +87 -0
- package/src/editor/js/commands/SetMaterialCommand.js +80 -0
- package/src/editor/js/commands/SetMaterialMapCommand.js +144 -0
- package/src/editor/js/commands/SetMaterialRangeCommand.js +92 -0
- package/src/editor/js/commands/SetMaterialValueCommand.js +91 -0
- package/src/editor/js/commands/SetMaterialVectorCommand.js +88 -0
- package/src/editor/js/commands/SetPositionCommand.js +84 -0
- package/src/editor/js/commands/SetRotationCommand.js +84 -0
- package/src/editor/js/commands/SetScaleCommand.js +84 -0
- package/src/editor/js/commands/SetSceneCommand.js +104 -0
- package/src/editor/js/commands/SetScriptValueCommand.js +80 -0
- package/src/editor/js/commands/SetShadowValueCommand.js +73 -0
- package/src/editor/js/commands/SetTextureParametersCommand.js +143 -0
- package/src/editor/js/commands/SetUuidCommand.js +70 -0
- package/src/editor/js/commands/SetValueCommand.js +75 -0
- package/src/editor/js/libs/acorn/acorn.js +3236 -0
- package/src/editor/js/libs/acorn/acorn_loose.js +1299 -0
- package/src/editor/js/libs/acorn/walk.js +344 -0
- package/src/editor/js/libs/app/index.html +51 -0
- package/src/editor/js/libs/app.js +14 -0
- package/src/editor/js/libs/codemirror/addon/dialog.css +32 -0
- package/src/editor/js/libs/codemirror/addon/dialog.js +163 -0
- package/src/editor/js/libs/codemirror/addon/show-hint.css +36 -0
- package/src/editor/js/libs/codemirror/addon/show-hint.js +529 -0
- package/src/editor/js/libs/codemirror/addon/tern.css +87 -0
- package/src/editor/js/libs/codemirror/addon/tern.js +750 -0
- package/src/editor/js/libs/codemirror/codemirror.css +344 -0
- package/src/editor/js/libs/codemirror/codemirror.js +9849 -0
- package/src/editor/js/libs/codemirror/mode/glsl.js +233 -0
- package/src/editor/js/libs/codemirror/mode/javascript.js +959 -0
- package/src/editor/js/libs/codemirror/theme/monokai.css +41 -0
- package/src/editor/js/libs/esprima.js +6401 -0
- package/src/editor/js/libs/jsonlint.js +453 -0
- package/src/editor/js/libs/signals.min.js +14 -0
- package/src/editor/js/libs/tern-threejs/build-defs.js +233 -0
- package/src/editor/js/libs/ternjs/comment.js +87 -0
- package/src/editor/js/libs/ternjs/def.js +588 -0
- package/src/editor/js/libs/ternjs/doc_comment.js +401 -0
- package/src/editor/js/libs/ternjs/infer.js +1635 -0
- package/src/editor/js/libs/ternjs/polyfill.js +80 -0
- package/src/editor/js/libs/ternjs/signal.js +26 -0
- package/src/editor/js/libs/ternjs/tern.js +993 -0
- package/src/editor/js/libs/ui.js +1305 -0
- package/src/editor/js/libs/ui.three.js +946 -0
- package/src/events.js +273 -0
- package/src/index.js +284 -0
- package/src/presets/machines.js +239 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Builds Tern definitions for the three.js API by scanning the JSDoc comments
|
|
2
|
+
// in a three.js build file (e.g. build/three.core.js).
|
|
3
|
+
//
|
|
4
|
+
// The build output is machine-formatted (one declaration per line, tab
|
|
5
|
+
// indentation, every documented symbol preceded by a `/** ... */` block), so a
|
|
6
|
+
// lightweight line scanner is enough — no full JS parser is required.
|
|
7
|
+
//
|
|
8
|
+
// Usage: const defs = buildDefs( sourceText );
|
|
9
|
+
//
|
|
10
|
+
// `defs` is a Tern definitions object of the shape consumed by the editor's
|
|
11
|
+
// TernServer: { "!name": "threejs", "THREE": { Box3: { prototype: { ... } } } }
|
|
12
|
+
|
|
13
|
+
// --- JSDoc type -> Tern type ------------------------------------------------
|
|
14
|
+
|
|
15
|
+
function mapType( raw, classes ) {
|
|
16
|
+
|
|
17
|
+
if ( ! raw ) return null;
|
|
18
|
+
|
|
19
|
+
let type = raw.trim();
|
|
20
|
+
|
|
21
|
+
// strip a single leading/trailing brace pair if present
|
|
22
|
+
type = type.replace( /^\{/, '' ).replace( /\}$/, '' ).trim();
|
|
23
|
+
|
|
24
|
+
// unions: Tern has no union type, take the first member
|
|
25
|
+
if ( type.includes( '|' ) ) type = type.split( '|' )[ 0 ].trim();
|
|
26
|
+
|
|
27
|
+
// nullable / non-nullable / rest markers
|
|
28
|
+
type = type.replace( /^[?!]/, '' ).replace( /^\.\.\./, '' ).trim();
|
|
29
|
+
|
|
30
|
+
// Array forms: Array<X>, Array.<X>, X[]
|
|
31
|
+
let m = type.match( /^Array\.?<(.+)>$/ );
|
|
32
|
+
if ( m ) return '[' + ( mapType( m[ 1 ], classes ) || '?' ) + ']';
|
|
33
|
+
m = type.match( /^(.+)\[\]$/ );
|
|
34
|
+
if ( m ) return '[' + ( mapType( m[ 1 ], classes ) || '?' ) + ']';
|
|
35
|
+
|
|
36
|
+
switch ( type ) {
|
|
37
|
+
|
|
38
|
+
case 'number': case 'string': case 'boolean': return type;
|
|
39
|
+
case 'function': case 'Function': return 'fn()';
|
|
40
|
+
case '*': case 'any': case 'Object': case 'object':
|
|
41
|
+
case 'undefined': case 'null': case 'void': return '?';
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ( classes.has( type ) ) return '+THREE.' + type;
|
|
46
|
+
|
|
47
|
+
return '?'; // unknown (TypedArray, external types, generics, …)
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --- JSDoc block parser -----------------------------------------------------
|
|
52
|
+
|
|
53
|
+
function parseDoc( lines ) {
|
|
54
|
+
|
|
55
|
+
const params = [];
|
|
56
|
+
let returns = null, atType = null, readonly = false;
|
|
57
|
+
const desc = [];
|
|
58
|
+
|
|
59
|
+
for ( let raw of lines ) {
|
|
60
|
+
|
|
61
|
+
const line = raw.replace( /^\s*\*?\s?/, '' ); // strip ` * `
|
|
62
|
+
|
|
63
|
+
const pm = line.match( /^@param\s+(\{[^}]*\})?\s*\[?([\w.]+)/ );
|
|
64
|
+
if ( pm ) { params.push( { type: pm[ 1 ] || null, name: pm[ 2 ].split( '.' )[ 0 ] } ); continue; }
|
|
65
|
+
|
|
66
|
+
const rm = line.match( /^@returns?\s+(\{[^}]*\})/ );
|
|
67
|
+
if ( rm ) { returns = rm[ 1 ]; continue; }
|
|
68
|
+
|
|
69
|
+
const tm = line.match( /^@type\s+(\{[^}]*\})/ );
|
|
70
|
+
if ( tm ) { atType = tm[ 1 ]; continue; }
|
|
71
|
+
|
|
72
|
+
if ( /^@readonly/.test( line ) ) { readonly = true; continue; }
|
|
73
|
+
if ( /^@/.test( line ) ) continue; // other tags ignored
|
|
74
|
+
|
|
75
|
+
if ( line.trim() ) desc.push( line.trim() );
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// de-duplicate rest params that share a base name
|
|
80
|
+
const seen = new Set(), uniqueParams = [];
|
|
81
|
+
for ( const p of params ) if ( ! seen.has( p.name ) ) { seen.add( p.name ); uniqueParams.push( p ); }
|
|
82
|
+
|
|
83
|
+
return { params: uniqueParams, returns, atType, readonly, doc: desc.join( ' ' ) };
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function fnType( doc, classes ) {
|
|
88
|
+
|
|
89
|
+
const args = doc.params.map( p => p.name + ': ' + ( mapType( p.type, classes ) || '?' ) ).join( ', ' );
|
|
90
|
+
let t = 'fn(' + args + ')';
|
|
91
|
+
const ret = mapType( doc.returns, classes );
|
|
92
|
+
if ( ret ) t += ' -> ' + ret;
|
|
93
|
+
return t;
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function entry( type, doc ) {
|
|
98
|
+
|
|
99
|
+
const e = { '!type': type };
|
|
100
|
+
if ( doc.doc ) e[ '!doc' ] = doc.doc;
|
|
101
|
+
return e;
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// --- main scan --------------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
export default function buildDefs( source ) {
|
|
108
|
+
|
|
109
|
+
const lines = source.split( '\n' );
|
|
110
|
+
|
|
111
|
+
// pass 1: collect class names (so types can resolve to +THREE.X)
|
|
112
|
+
const classes = new Set();
|
|
113
|
+
for ( const line of lines ) {
|
|
114
|
+
|
|
115
|
+
const m = line.match( /^class\s+(\w+)/ );
|
|
116
|
+
if ( m ) classes.add( m[ 1 ] );
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const THREE = {};
|
|
121
|
+
let cur = null; // current class def object
|
|
122
|
+
let curName = null; // current class name
|
|
123
|
+
let pending = null; // most recent parsed JSDoc block
|
|
124
|
+
|
|
125
|
+
for ( let i = 0; i < lines.length; i ++ ) {
|
|
126
|
+
|
|
127
|
+
const line = lines[ i ];
|
|
128
|
+
|
|
129
|
+
// JSDoc block: collect then resolve against the next code line below
|
|
130
|
+
const t = line.trim();
|
|
131
|
+
if ( t.startsWith( '/**' ) ) {
|
|
132
|
+
|
|
133
|
+
const block = [];
|
|
134
|
+
if ( ! t.endsWith( '*/' ) ) {
|
|
135
|
+
|
|
136
|
+
i ++;
|
|
137
|
+
for ( ; i < lines.length; i ++ ) {
|
|
138
|
+
|
|
139
|
+
if ( lines[ i ].trim().endsWith( '*/' ) ) break;
|
|
140
|
+
block.push( lines[ i ] );
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
pending = parseDoc( block );
|
|
147
|
+
continue;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// class declaration
|
|
152
|
+
const cm = line.match( /^class\s+(\w+)(?:\s+extends\s+(\w+))?/ );
|
|
153
|
+
if ( cm ) {
|
|
154
|
+
|
|
155
|
+
curName = cm[ 1 ];
|
|
156
|
+
cur = THREE[ curName ] || ( THREE[ curName ] = {} );
|
|
157
|
+
// Declaring the class with a function `!type` makes Tern treat it as a
|
|
158
|
+
// constructor, so `new THREE.X()` resolves to X.prototype. The signature
|
|
159
|
+
// is refined once the constructor's JSDoc is read.
|
|
160
|
+
cur[ '!type' ] = 'fn()';
|
|
161
|
+
cur.prototype = cur.prototype || {};
|
|
162
|
+
if ( cm[ 2 ] && classes.has( cm[ 2 ] ) ) cur.prototype[ '!proto' ] = 'THREE.' + cm[ 2 ] + '.prototype';
|
|
163
|
+
if ( pending && pending.doc ) cur[ '!doc' ] = pending.doc;
|
|
164
|
+
pending = null;
|
|
165
|
+
continue;
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// end of a top-level class
|
|
170
|
+
if ( line === '}' ) { cur = null; curName = null; pending = null; continue; }
|
|
171
|
+
|
|
172
|
+
if ( ! cur || ! pending ) { if ( t === '' ) continue; pending = null; continue; }
|
|
173
|
+
|
|
174
|
+
// inside a class, the line right after a JSDoc block:
|
|
175
|
+
|
|
176
|
+
// instance field: \t\tthis.name =
|
|
177
|
+
let m = line.match( /^\t\tthis\.(\w+)\s*=/ );
|
|
178
|
+
if ( m ) {
|
|
179
|
+
|
|
180
|
+
const ty = mapType( pending.atType, classes ) || '?';
|
|
181
|
+
cur.prototype[ m[ 1 ] ] = entry( ty, pending );
|
|
182
|
+
pending = null;
|
|
183
|
+
continue;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// static method: \tstatic name(
|
|
188
|
+
m = line.match( /^\tstatic\s+(\w+)\s*\(/ );
|
|
189
|
+
if ( m ) {
|
|
190
|
+
|
|
191
|
+
cur[ m[ 1 ] ] = entry( fnType( pending, classes ), pending );
|
|
192
|
+
pending = null;
|
|
193
|
+
continue;
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// accessor: \tget name() / \tset name(
|
|
198
|
+
m = line.match( /^\t(?:get|set)\s+(\w+)\s*\(/ );
|
|
199
|
+
if ( m ) {
|
|
200
|
+
|
|
201
|
+
const ty = mapType( pending.atType || pending.returns, classes ) || '?';
|
|
202
|
+
if ( ! cur.prototype[ m[ 1 ] ] ) cur.prototype[ m[ 1 ] ] = entry( ty, pending );
|
|
203
|
+
pending = null;
|
|
204
|
+
continue;
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// constructor: \tconstructor( -> refine the class signature
|
|
209
|
+
if ( /^\tconstructor\s*\(/.test( line ) ) {
|
|
210
|
+
|
|
211
|
+
cur[ '!type' ] = 'fn(' + pending.params.map( p => p.name + ': ' + ( mapType( p.type, classes ) || '?' ) ).join( ', ' ) + ')';
|
|
212
|
+
pending = null;
|
|
213
|
+
continue;
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// instance method: \t[async ]name(
|
|
218
|
+
m = line.match( /^\t(?:async\s+)?(\w+)\s*\(/ );
|
|
219
|
+
if ( m ) {
|
|
220
|
+
|
|
221
|
+
cur.prototype[ m[ 1 ] ] = entry( fnType( pending, classes ), pending );
|
|
222
|
+
pending = null;
|
|
223
|
+
continue;
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
pending = null;
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return { '!name': 'threejs', THREE };
|
|
232
|
+
|
|
233
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
(function(mod) {
|
|
2
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
3
|
+
return mod(exports);
|
|
4
|
+
if (typeof define == "function" && define.amd) // AMD
|
|
5
|
+
return define(["exports"], mod);
|
|
6
|
+
mod(tern.comment || (tern.comment = {}));
|
|
7
|
+
})(function(exports) {
|
|
8
|
+
function isSpace(ch) {
|
|
9
|
+
return (ch < 14 && ch > 8) || ch === 32 || ch === 160;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function onOwnLine(text, pos) {
|
|
13
|
+
for (; pos > 0; --pos) {
|
|
14
|
+
var ch = text.charCodeAt(pos - 1);
|
|
15
|
+
if (ch == 10) break;
|
|
16
|
+
if (!isSpace(ch)) return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Gather comments directly before a function
|
|
22
|
+
exports.commentsBefore = function(text, pos) {
|
|
23
|
+
var found = null, emptyLines = 0, topIsLineComment;
|
|
24
|
+
out: while (pos > 0) {
|
|
25
|
+
var prev = text.charCodeAt(pos - 1);
|
|
26
|
+
if (prev == 10) {
|
|
27
|
+
for (var scan = --pos, sawNonWS = false; scan > 0; --scan) {
|
|
28
|
+
prev = text.charCodeAt(scan - 1);
|
|
29
|
+
if (prev == 47 && text.charCodeAt(scan - 2) == 47) {
|
|
30
|
+
if (!onOwnLine(text, scan - 2)) break out;
|
|
31
|
+
var content = text.slice(scan, pos);
|
|
32
|
+
if (!emptyLines && topIsLineComment) found[0] = content + "\n" + found[0];
|
|
33
|
+
else (found || (found = [])).unshift(content);
|
|
34
|
+
topIsLineComment = true;
|
|
35
|
+
emptyLines = 0;
|
|
36
|
+
pos = scan - 2;
|
|
37
|
+
break;
|
|
38
|
+
} else if (prev == 10) {
|
|
39
|
+
if (!sawNonWS && ++emptyLines > 1) break out;
|
|
40
|
+
break;
|
|
41
|
+
} else if (!sawNonWS && !isSpace(prev)) {
|
|
42
|
+
sawNonWS = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else if (prev == 47 && text.charCodeAt(pos - 2) == 42) {
|
|
46
|
+
for (var scan = pos - 2; scan > 1; --scan) {
|
|
47
|
+
if (text.charCodeAt(scan - 1) == 42 && text.charCodeAt(scan - 2) == 47) {
|
|
48
|
+
if (!onOwnLine(text, scan - 2)) break out;
|
|
49
|
+
(found || (found = [])).unshift(text.slice(scan, pos - 2));
|
|
50
|
+
topIsLineComment = false;
|
|
51
|
+
emptyLines = 0;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
pos = scan - 2;
|
|
56
|
+
} else if (isSpace(prev)) {
|
|
57
|
+
--pos;
|
|
58
|
+
} else {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return found;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.commentAfter = function(text, pos) {
|
|
66
|
+
while (pos < text.length) {
|
|
67
|
+
var next = text.charCodeAt(pos);
|
|
68
|
+
if (next == 47) {
|
|
69
|
+
var after = text.charCodeAt(pos + 1), end;
|
|
70
|
+
if (after == 47) // line comment
|
|
71
|
+
end = text.indexOf("\n", pos + 2);
|
|
72
|
+
else if (after == 42) // block comment
|
|
73
|
+
end = text.indexOf("*/", pos + 2);
|
|
74
|
+
else
|
|
75
|
+
return;
|
|
76
|
+
return text.slice(pos + 2, end < 0 ? text.length : end);
|
|
77
|
+
} else if (isSpace(next)) {
|
|
78
|
+
++pos;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.ensureCommentsBefore = function(text, node) {
|
|
84
|
+
if (node.hasOwnProperty("commentsBefore")) return node.commentsBefore;
|
|
85
|
+
return node.commentsBefore = exports.commentsBefore(text, node.start);
|
|
86
|
+
};
|
|
87
|
+
});
|