Example #1
0
	imports.forEach( x => {
		let moduleId = x.path;
		let name;

		moduleId = x.path;

		// use existing value
		if ( hasOwnProp.call( nameById, moduleId ) ) {
			x.name = nameById[ moduleId ];
			return;
		}

		// if user supplied a function, defer to it
		if ( userFn && ( name = userFn( moduleId ) ) ) {
			name = sanitize( name );

			if ( hasOwnProp.call( usedNames, name ) ) {
				// TODO write a test for this
				throw new Error( `Naming collision: module ${moduleId} cannot be called ${name}` );
			}
		}

		else {
			let parts = splitPath( moduleId );
			let i;
			let prefix = '';
			let candidate;

			do {
				i = parts.length;
				while ( i-- > 0 ) {
					candidate = prefix + sanitize( parts.slice( i ).join( '__' ) );

					if ( !hasOwnProp.call( usedNames, candidate ) ) {
						name = candidate;
						break;
					}
				}

				prefix += '_';
			} while ( !name );
		}

		usedNames[ name ] = true;
		nameById[ moduleId ] = name;

		x.name = name;
	});
	modules.concat( externalModules ).forEach( mod => {
		// is this already named?
		if ( hasOwnProp.call( names, mod.id ) ) {
			mod.name = names[ mod.id ];
			return;
		}

		let name;
		let parts = splitPath( mod.id );
		let i = parts.length;

		while ( i-- ) {
			name = sanitize( parts.slice( i ).join( '_' ) );

			if ( !hasOwnProp.call( used, name ) ) {
				break;
			}
		}

		while ( hasOwnProp.call( used, name ) ) {
			name = '_' + name;
		}

		used[ name ] = true;
		mod.name = name;
	});
Example #3
0
function sanitizeInputs() {
    this.payload.notes = sanitize( this.payload.notes );
    this.payload.description = sanitize( this.payload.description );
}