Skip to content

Commit f6aae66

Browse files
authored
Merge pull request #17204 from Mugen87/dev34
Remove remaining IIFEs from core.
2 parents f76f357 + 518d246 commit f6aae66

File tree

7 files changed

+588
-687
lines changed

7 files changed

+588
-687
lines changed

src/Three.Legacy.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,10 @@ Object.assign( Matrix4.prototype, {
594594
},
595595
getPosition: function () {
596596

597-
var v1;
597+
console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
598+
return new Vector3().setFromMatrixColumn( this, 3 );
598599

599-
return function getPosition() {
600-
601-
if ( v1 === undefined ) v1 = new Vector3();
602-
console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
603-
return v1.setFromMatrixColumn( this, 3 );
604-
605-
};
606-
607-
}(),
600+
},
608601
setRotationFromQuaternion: function ( q ) {
609602

610603
console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );

src/animation/PropertyBinding.js

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
*/
1010

1111
// Characters [].:/ are reserved for track binding syntax.
12-
var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
12+
var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
13+
14+
var _reservedRe;
15+
var _trackRe, _supportedObjectNames;
1316

1417
function Composite( targetGroup, path, optionalParsedPath ) {
1518

@@ -109,101 +112,101 @@ Object.assign( PropertyBinding, {
109112
* @param {string} name Node name to be sanitized.
110113
* @return {string}
111114
*/
112-
sanitizeNodeName: ( function () {
115+
sanitizeNodeName: function ( name ) {
113116

114-
var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
117+
if ( _reservedRe === undefined ) {
115118

116-
return function sanitizeNodeName( name ) {
119+
_reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
117120

118-
return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
121+
}
119122

120-
};
123+
return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
121124

122-
}() ),
125+
},
123126

124-
parseTrackName: function () {
127+
parseTrackName: function ( trackName ) {
125128

126-
// Attempts to allow node names from any language. ES5's `\w` regexp matches
127-
// only latin characters, and the unicode \p{L} is not yet supported. So
128-
// instead, we exclude reserved characters and match everything else.
129-
var wordChar = '[^' + RESERVED_CHARS_RE + ']';
130-
var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
129+
if ( _supportedObjectNames === undefined ) {
131130

132-
// Parent directories, delimited by '/' or ':'. Currently unused, but must
133-
// be matched to parse the rest of the track name.
134-
var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
131+
// Attempts to allow node names from any language. ES5's `\w` regexp matches
132+
// only latin characters, and the unicode \p{L} is not yet supported. So
133+
// instead, we exclude reserved characters and match everything else.
134+
var wordChar = '[^' + _RESERVED_CHARS_RE + ']';
135+
var wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
135136

136-
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
137-
var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
137+
// Parent directories, delimited by '/' or ':'. Currently unused, but must
138+
// be matched to parse the rest of the track name.
139+
var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
138140

139-
// Object on target node, and accessor. May not contain reserved
140-
// characters. Accessor may contain any character except closing bracket.
141-
var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
141+
// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
142+
var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
142143

143-
// Property and accessor. May not contain reserved characters. Accessor may
144-
// contain any non-bracket characters.
145-
var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
144+
// Object on target node, and accessor. May not contain reserved
145+
// characters. Accessor may contain any character except closing bracket.
146+
var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
146147

147-
var trackRe = new RegExp( ''
148-
+ '^'
149-
+ directoryRe
150-
+ nodeRe
151-
+ objectRe
152-
+ propertyRe
153-
+ '$'
154-
);
148+
// Property and accessor. May not contain reserved characters. Accessor may
149+
// contain any non-bracket characters.
150+
var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
155151

156-
var supportedObjectNames = [ 'material', 'materials', 'bones' ];
152+
_trackRe = new RegExp( ''
153+
+ '^'
154+
+ directoryRe
155+
+ nodeRe
156+
+ objectRe
157+
+ propertyRe
158+
+ '$'
159+
);
157160

158-
return function parseTrackName( trackName ) {
161+
_supportedObjectNames = [ 'material', 'materials', 'bones' ];
159162

160-
var matches = trackRe.exec( trackName );
163+
}
161164

162-
if ( ! matches ) {
165+
var matches = _trackRe.exec( trackName );
163166

164-
throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
167+
if ( ! matches ) {
165168

166-
}
169+
throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
167170

168-
var results = {
169-
// directoryName: matches[ 1 ], // (tschw) currently unused
170-
nodeName: matches[ 2 ],
171-
objectName: matches[ 3 ],
172-
objectIndex: matches[ 4 ],
173-
propertyName: matches[ 5 ], // required
174-
propertyIndex: matches[ 6 ]
175-
};
171+
}
176172

177-
var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
173+
var results = {
174+
// directoryName: matches[ 1 ], // (tschw) currently unused
175+
nodeName: matches[ 2 ],
176+
objectName: matches[ 3 ],
177+
objectIndex: matches[ 4 ],
178+
propertyName: matches[ 5 ], // required
179+
propertyIndex: matches[ 6 ]
180+
};
178181

179-
if ( lastDot !== undefined && lastDot !== - 1 ) {
182+
var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
180183

181-
var objectName = results.nodeName.substring( lastDot + 1 );
184+
if ( lastDot !== undefined && lastDot !== - 1 ) {
182185

183-
// Object names must be checked against a whitelist. Otherwise, there
184-
// is no way to parse 'foo.bar.baz': 'baz' must be a property, but
185-
// 'bar' could be the objectName, or part of a nodeName (which can
186-
// include '.' characters).
187-
if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
186+
var objectName = results.nodeName.substring( lastDot + 1 );
188187

189-
results.nodeName = results.nodeName.substring( 0, lastDot );
190-
results.objectName = objectName;
188+
// Object names must be checked against a whitelist. Otherwise, there
189+
// is no way to parse 'foo.bar.baz': 'baz' must be a property, but
190+
// 'bar' could be the objectName, or part of a nodeName (which can
191+
// include '.' characters).
192+
if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
191193

192-
}
194+
results.nodeName = results.nodeName.substring( 0, lastDot );
195+
results.objectName = objectName;
193196

194197
}
195198

196-
if ( results.propertyName === null || results.propertyName.length === 0 ) {
199+
}
197200

198-
throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
201+
if ( results.propertyName === null || results.propertyName.length === 0 ) {
199202

200-
}
203+
throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
201204

202-
return results;
205+
}
203206

204-
};
207+
return results;
205208

206-
}(),
209+
},
207210

208211
findNode: function ( root, nodeName ) {
209212

0 commit comments

Comments
 (0)