Browse Source

Merge pull request #237 from rollup/js-extensions

add js extensions
better-aggressive
Rich Harris 9 years ago
parent
commit
b3ca349eeb
  1. 26
      src/Bundle.js
  2. 4
      src/ExternalModule.js
  3. 18
      src/Module.js
  4. 6
      src/Statement.js
  5. 2
      src/ast/Scope.js
  6. 2
      src/ast/attachScopes.js
  7. 6
      src/finalisers/amd.js
  8. 2
      src/finalisers/cjs.js
  9. 2
      src/finalisers/es6.js
  10. 8
      src/finalisers/iife.js
  11. 10
      src/finalisers/index.js
  12. 8
      src/finalisers/umd.js
  13. 10
      src/rollup.js
  14. 4
      src/utils/defaults.js
  15. 2
      src/utils/first.js
  16. 4
      src/utils/fs.js
  17. 2
      src/utils/getExportMode.js
  18. 2
      src/utils/makeLegalIdentifier.js

26
src/Bundle.js

@ -1,17 +1,17 @@
import Promise from 'es6-promise/lib/es6-promise/promise';
import Promise from 'es6-promise/lib/es6-promise/promise.js';
import MagicString from 'magic-string';
import first from './utils/first';
import { blank, keys } from './utils/object';
import Module from './Module';
import ExternalModule from './ExternalModule';
import finalisers from './finalisers/index';
import ensureArray from './utils/ensureArray';
import { load, onwarn, resolveId } from './utils/defaults';
import getExportMode from './utils/getExportMode';
import getIndentString from './utils/getIndentString';
import { unixizePath } from './utils/normalizePlatform';
import transform from './utils/transform';
import collapseSourcemaps from './utils/collapseSourcemaps';
import first from './utils/first.js';
import { blank, keys } from './utils/object.js';
import Module from './Module.js';
import ExternalModule from './ExternalModule.js';
import finalisers from './finalisers/index.js';
import ensureArray from './utils/ensureArray.js';
import { load, onwarn, resolveId } from './utils/defaults.js';
import getExportMode from './utils/getExportMode.js';
import getIndentString from './utils/getIndentString.js';
import { unixizePath } from './utils/normalizePlatform.js';
import transform from './utils/transform.js';
import collapseSourcemaps from './utils/collapseSourcemaps.js';
export default class Bundle {
constructor ( options ) {

4
src/ExternalModule.js

@ -1,5 +1,5 @@
import { blank } from './utils/object';
import makeLegalIdentifier from './utils/makeLegalIdentifier';
import { blank } from './utils/object.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
class ExternalDeclaration {
constructor ( module, name ) {

18
src/Module.js

@ -1,12 +1,12 @@
import { parse } from 'acorn/src/index';
import { parse } from 'acorn/src/index.js';
import MagicString from 'magic-string';
import { walk } from 'estree-walker';
import Statement from './Statement';
import { blank, keys } from './utils/object';
import { basename, extname } from './utils/path';
import getLocation from './utils/getLocation';
import makeLegalIdentifier from './utils/makeLegalIdentifier';
import SOURCEMAPPING_URL from './utils/sourceMappingURL';
import Statement from './Statement.js';
import { blank, keys } from './utils/object.js';
import { basename, extname } from './utils/path.js';
import getLocation from './utils/getLocation.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
class SyntheticDefaultDeclaration {
constructor ( node, statement, name ) {
@ -176,7 +176,7 @@ export default class Module {
const node = statement.node;
const source = node.source && node.source.value;
// export { name } from './other'
// export { name } from './other.js'
if ( source ) {
if ( !~this.dependencies.indexOf( source ) ) this.dependencies.push( source );
@ -697,7 +697,7 @@ export default class Module {
}
traceExport ( name, importer ) {
// export { foo } from './other'
// export { foo } from './other.js'
const reexportDeclaration = this.reexports[ name ];
if ( reexportDeclaration ) {
return reexportDeclaration.module.traceExport( reexportDeclaration.localName, this );

6
src/Statement.js

@ -1,7 +1,7 @@
import { walk } from 'estree-walker';
import Scope from './ast/Scope';
import attachScopes from './ast/attachScopes';
import getLocation from './utils/getLocation';
import Scope from './ast/Scope.js';
import attachScopes from './ast/attachScopes.js';
import getLocation from './utils/getLocation.js';
const modifierNodes = {
AssignmentExpression: 'left',

2
src/ast/Scope.js

@ -1,4 +1,4 @@
import { blank, keys } from '../utils/object';
import { blank, keys } from '../utils/object.js';
const extractors = {
Identifier ( names, param ) {

2
src/ast/attachScopes.js

@ -1,5 +1,5 @@
import { walk } from 'estree-walker';
import Scope from './Scope';
import Scope from './Scope.js';
const blockDeclarations = {
'const': true,

6
src/finalisers/amd.js

@ -1,6 +1,6 @@
import { getName, quoteId } from '../utils/map-helpers';
import getInteropBlock from './shared/getInteropBlock';
import getExportBlock from './shared/getExportBlock';
import { getName, quoteId } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
export default function amd ( bundle, magicString, { exportMode, indentString }, options ) {
let deps = bundle.externalModules.map( quoteId );

2
src/finalisers/cjs.js

@ -1,4 +1,4 @@
import getExportBlock from './shared/getExportBlock';
import getExportBlock from './shared/getExportBlock.js';
export default function cjs ( bundle, magicString, { exportMode }, options ) {
let intro = options.useStrict === false ? `` : `'use strict';\n\n`;

2
src/finalisers/es6.js

@ -1,4 +1,4 @@
import { keys } from '../utils/object';
import { keys } from '../utils/object.js';
function notDefault ( name ) {
return name !== 'default';

8
src/finalisers/iife.js

@ -1,7 +1,7 @@
import { blank } from '../utils/object';
import { getName } from '../utils/map-helpers';
import getInteropBlock from './shared/getInteropBlock';
import getExportBlock from './shared/getExportBlock';
import { blank } from '../utils/object.js';
import { getName } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
export default function iife ( bundle, magicString, { exportMode, indentString }, options ) {
const globalNames = options.globals || blank();

10
src/finalisers/index.js

@ -1,7 +1,7 @@
import amd from './amd';
import cjs from './cjs';
import es6 from './es6';
import iife from './iife';
import umd from './umd';
import amd from './amd.js';
import cjs from './cjs.js';
import es6 from './es6.js';
import iife from './iife.js';
import umd from './umd.js';
export default { amd, cjs, es6, iife, umd };

8
src/finalisers/umd.js

@ -1,7 +1,7 @@
import { blank } from '../utils/object';
import { getName, quoteId, req } from '../utils/map-helpers';
import getInteropBlock from './shared/getInteropBlock';
import getExportBlock from './shared/getExportBlock';
import { blank } from '../utils/object.js';
import { getName, quoteId, req } from '../utils/map-helpers.js';
import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js';
export default function umd ( bundle, magicString, { exportMode, indentString }, options ) {
if ( exportMode !== 'none' && !options.moduleName ) {

10
src/rollup.js

@ -1,8 +1,8 @@
import { basename } from './utils/path';
import { writeFile } from './utils/fs';
import { keys } from './utils/object';
import SOURCEMAPPING_URL from './utils/sourceMappingURL';
import Bundle from './Bundle';
import { basename } from './utils/path.js';
import { writeFile } from './utils/fs.js';
import { keys } from './utils/object.js';
import SOURCEMAPPING_URL from './utils/sourceMappingURL.js';
import Bundle from './Bundle.js';
export const VERSION = '<@VERSION@>';

4
src/utils/defaults.js

@ -1,5 +1,5 @@
import { readFileSync } from './fs';
import { dirname, extname, isAbsolute, resolve } from './path';
import { readFileSync } from './fs.js';
import { dirname, extname, isAbsolute, resolve } from './path.js';
export function load ( id ) {
return readFileSync( id, 'utf-8' );

2
src/utils/first.js

@ -1,4 +1,4 @@
import Promise from 'es6-promise/lib/es6-promise/promise';
import Promise from 'es6-promise/lib/es6-promise/promise.js';
// Return the first non-falsy result from an array of
// maybe-sync, maybe-promise-returning functions

4
src/utils/fs.js

@ -1,6 +1,6 @@
import Promise from 'es6-promise/lib/es6-promise/promise';
import Promise from 'es6-promise/lib/es6-promise/promise.js';
import * as fs from 'fs';
import { dirname } from './path';
import { dirname } from './path.js';
function mkdirpath ( path ) {
const dir = dirname( path );

2
src/utils/getExportMode.js

@ -1,4 +1,4 @@
import { keys } from './object';
import { keys } from './object.js';
function badExports ( option, keys ) {
throw new Error( `'${option}' was specified for options.exports, but entry module has following exports: ${keys.join(', ')}` );

2
src/utils/makeLegalIdentifier.js

@ -1,4 +1,4 @@
import { blank } from './object';
import { blank } from './object.js';
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
const builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );

Loading…
Cancel
Save