Removes last UMDs from the modules.

This commit is contained in:
Yury Delendik 2017-05-30 20:38:22 -05:00
parent e51718711b
commit 66c8893815
28 changed files with 71 additions and 224 deletions

View File

@ -0,0 +1,7 @@
import { Test } from 'import-name';
import { Test2 } from './non-alias';
export {
Test3
} from 'import-name';
var Imp = require('import-name');
var Imp2 = require('./non-alias');

View File

@ -0,0 +1,5 @@
import { Test } from 'import-alias';
import { Test2 } from './non-alias';
export { Test3 } from 'import-alias';
var Imp = require('import-alias');
var Imp2 = require('./non-alias');

View File

@ -1,5 +0,0 @@
'use strict';
var aB = require('../a/b.js');
var cD = require('./d.js');
var opt;
opt(aB + cD);

View File

@ -1,14 +0,0 @@
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('test', ['exports', 'a/b', 'c/d'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../a/b.js'), require('./d.js'));
} else {
factory((root.E = {}), root.aB, root.cD);
}
}(this, function (exports, aB, cD, opt) {
opt(aB + cD);
}));

View File

@ -80,6 +80,14 @@ function handlePreprocessorAction(ctx, actionName, args, loc) {
function postprocessNode(ctx, node) {
switch (node.type) {
case 'ExportNamedDeclaration':
case 'ImportDeclaration':
if (node.source && node.source.type === 'Literal' &&
ctx.map && ctx.map[node.source.value]) {
var newValue = ctx.map[node.source.value];
node.source.value = node.source.raw = newValue;
}
break;
case 'IfStatement':
if (isLiteral(node.test, true)) {
// if (true) stmt1; => stmt1
@ -165,6 +173,13 @@ function postprocessNode(ctx, node) {
return handlePreprocessorAction(ctx, action,
node.arguments, node.loc);
}
// require('string')
if (node.callee.type === 'Identifier' && node.callee.name === 'require' &&
node.arguments.length === 1 && node.arguments[0].type === 'Literal' &&
ctx.map && ctx.map[node.arguments[0].value]) {
var requireName = node.arguments[0];
requireName.value = requireName.raw = ctx.map[requireName.value];
}
break;
case 'BlockStatement':
var subExpressionIndex = 0;
@ -201,86 +216,6 @@ function postprocessNode(ctx, node) {
block.body.pop();
}
break;
case 'Program':
// Checking for a function closure that looks like UMD header.
node.body.some(function (item, index) {
// Is it `(function (root, factory) { ? }(this, function (?) {?}));` ?
if (item.type !== 'ExpressionStatement' ||
item.expression.type !== 'CallExpression' ||
item.expression.callee.type !== 'FunctionExpression' ||
item.expression.callee.params.length !== 2 ||
item.expression.arguments.length !== 2 ||
item.expression.arguments[0].type !== 'ThisExpression' ||
item.expression.arguments[1].type !== 'FunctionExpression') {
return false;
}
var init = item.expression.callee;
// Is init body looks like
// `if (?) { ? } else if (typeof exports !== 'undefined') { ? } ...`?
if (init.body.type !== 'BlockStatement' ||
init.body.body.length !== 1 ||
init.body.body[0].type !== 'IfStatement') {
return false;
}
var initIf = init.body.body[0];
if (initIf.alternate.type !== 'IfStatement' ||
initIf.alternate.test.type !== 'BinaryExpression' ||
initIf.alternate.test.operator !== '!==' ||
initIf.alternate.test.left.type !== 'UnaryExpression' ||
initIf.alternate.test.left.operator !== 'typeof' ||
initIf.alternate.test.left.argument.type !== 'Identifier' ||
initIf.alternate.test.left.argument.name !== 'exports' ||
initIf.alternate.test.right.type !== 'Literal' ||
initIf.alternate.test.right.value !== 'undefined' ||
initIf.alternate.consequent.type !== 'BlockStatement') {
return false;
}
var commonJsInit = initIf.alternate.consequent;
// Is commonJsInit `factory(exports, ...)` ?
if (commonJsInit.body.length !== 1 ||
commonJsInit.body[0].type !== 'ExpressionStatement' ||
commonJsInit.body[0].expression.type !== 'CallExpression' ||
commonJsInit.body[0].expression.callee.type !== 'Identifier') {
return false;
}
var commonJsInitArgs = commonJsInit.body[0].expression.arguments;
if (commonJsInitArgs.length === 0 ||
commonJsInitArgs[0].type !== 'Identifier' ||
commonJsInitArgs[0].name !== 'exports') {
return false;
}
var factory = item.expression.arguments[1];
// Is factory `function (exports, ....) { ? }` ?
if (factory.params.length === 0 ||
factory.params[0].type !== 'Identifier' ||
factory.params[0].name !== 'exports' ||
factory.body.type !== 'BlockStatement') {
return true;
}
var factoryParams = factory.params;
var factoryBody = factory.body;
// Remove closure and function and replacing parameters with vars.
node.body.splice(index, 1);
for (var i = 1, ii = factoryParams.length; i < ii; i++) {
var varNode = {
type: 'VariableDeclaration',
'declarations': [{
type: 'VariableDeclarator',
id: factoryParams[i],
init: commonJsInitArgs[i] || null,
loc: factoryParams[i].loc
}],
kind: 'var'
};
node.body.splice(index++, 0, varNode);
}
factoryBody.body.forEach(function (item) {
node.body.splice(index++, 0, item);
});
return true;
});
break;
}
return node;
}

View File

@ -24,8 +24,12 @@ files.forEach(function(expectationFilename) {
OBJ: {obj: {i: 1}, j: 2},
TEXT: 'text'
};
var map = {
'import-alias': 'import-name',
};
var ctx = {
defines: defines,
map: map,
rootPath: __dirname + '/../..',
};
var out;

View File

@ -142,6 +142,7 @@ function createWebpackConfig(defines, output) {
alias: {
'pdfjs': path.join(__dirname, 'src'),
'pdfjs-web': path.join(__dirname, 'web'),
'pdfjs-lib': path.join(__dirname, 'web/pdfjs'),
}
},
devtool: enableSourceMaps ? 'source-map' : undefined,
@ -1008,7 +1009,10 @@ gulp.task('lib', ['buildnumber'], function () {
LIB: true,
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit
})
}),
map: {
'pdfjs-lib': '../pdf'
}
};
var licenseHeader = fs.readFileSync('./src/license_header.js').toString();
var preprocessor2 = require('./external/builder/preprocessor2.js');
@ -1021,6 +1025,7 @@ gulp.task('lib', ['buildnumber'], function () {
], {base: 'src/'}),
gulp.src([
'web/*.js',
'!web/pdfjs.js',
'!web/viewer.js',
'!web/compatibility.js',
], {base: '.'}),

View File

@ -1,72 +0,0 @@
/* Copyright 2015 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs/main_loader', ['exports', 'pdfjs/display/api',
'pdfjs/display/annotation_layer', 'pdfjs/display/text_layer',
'pdfjs/display/dom_utils', 'pdfjs/shared/util', 'pdfjs/display/svg',
'pdfjs/display/global'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('./display/api.js'),
require('./display/annotation_layer.js'),
require('./display/text_layer.js'), require('./display/dom_utils.js'),
require('./shared/util.js'), require('./display/svg.js'),
require('./display/global.js'));
} else {
factory((root.pdfjsMainLoader = {}), root.pdfjsDisplayAPI,
root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer,
root.pdfjsDisplayDOMUtils, root.pdfjsSharedUtil, root.pdfjsDisplaySVG,
root.pdfjsDisplayGlobal);
}
}(this, function (exports, displayAPI, displayAnnotationLayer,
displayTextLayer, displayDOMUtils, sharedUtil,
displaySVG, displayGlobal) {
// Sync the exports below with ./pdf.js file/template.
exports.PDFJS = displayGlobal.PDFJS;
exports.build = displayAPI.build;
exports.version = displayAPI.version;
exports.getDocument = displayAPI.getDocument;
exports.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
exports.LoopbackPort = displayAPI.LoopbackPort;
exports.PDFWorker = displayAPI.PDFWorker;
exports.renderTextLayer = displayTextLayer.renderTextLayer;
exports.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
exports.CustomStyle = displayDOMUtils.CustomStyle;
exports.createPromiseCapability = sharedUtil.createPromiseCapability;
exports.PasswordResponses = sharedUtil.PasswordResponses;
exports.InvalidPDFException = sharedUtil.InvalidPDFException;
exports.MissingPDFException = sharedUtil.MissingPDFException;
exports.SVGGraphics = displaySVG.SVGGraphics;
exports.NativeImageDecoding = sharedUtil.NativeImageDecoding;
exports.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
exports.OPS = sharedUtil.OPS;
exports.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
exports.isValidUrl = displayDOMUtils.isValidUrl;
exports.createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
exports.createObjectURL = sharedUtil.createObjectURL;
exports.removeNullCharacters = sharedUtil.removeNullCharacters;
exports.shadow = sharedUtil.shadow;
exports.createBlob = sharedUtil.createBlob;
exports.RenderingCancelledException =
displayDOMUtils.RenderingCancelledException;
exports.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
exports.addLinkAttributes = displayDOMUtils.addLinkAttributes;
exports.StatTimer = sharedUtil.StatTimer;
}));

View File

@ -16,8 +16,10 @@
'use strict';
var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
var pdfjsVersion =
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : void 0;
var pdfjsBuild =
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_BUILD') : void 0;
var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js');

View File

@ -49,6 +49,7 @@
'pdfjs': new URL('src', baseLocation).href,
'pdfjs-web': new URL('web', baseLocation).href,
'pdfjs-test': new URL('test', baseLocation).href,
'pdfjs-lib': new URL('src/pdf', baseLocation).href,
},
meta: {
'*': {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { AnnotationLayer } from './pdfjs';
import { AnnotationLayer } from 'pdfjs-lib';
import { mozL10n } from './ui_utils';
import { SimpleLinkService } from './pdf_link_service';

View File

@ -23,7 +23,7 @@ import {
build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException,
MissingPDFException, OPS, PDFJS, shadow, UnexpectedResponseException,
UNSUPPORTED_FEATURES, version,
} from './pdfjs';
} from 'pdfjs-lib';
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
import { PDFSidebar, SidebarView } from './pdf_sidebar';

View File

@ -17,7 +17,7 @@
import { DefaultExternalServices, PDFViewerApplication } from './app';
import { BasePreferences } from './preferences';
import { DownloadManager } from './download_manager';
import { PDFJS } from './pdfjs';
import { PDFJS } from 'pdfjs-lib';
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) {
throw new Error('Module "pdfjs-web/chromecom" shall not be used outside ' +

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createObjectURL, createValidAbsoluteUrl, PDFJS } from './pdfjs';
import { createObjectURL, createValidAbsoluteUrl, PDFJS } from 'pdfjs-lib';
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('CHROME || GENERIC')) {
throw new Error('Module "pdfjs-web/download_manager" shall not be used ' +

View File

@ -15,7 +15,7 @@
import { CSS_UNITS } from './ui_utils';
import { PDFPrintServiceFactory } from './app';
import { shadow } from './pdfjs';
import { shadow } from 'pdfjs-lib';
// Creates a placeholder with div and canvas with right size for the page.
function composePage(pdfDocument, pageNumber, size, printContainer) {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createObjectURL, PDFDataRangeTransport, shadow } from './pdfjs';
import { createObjectURL, PDFDataRangeTransport, shadow } from 'pdfjs-lib';
import { BasePreferences } from './preferences';
import { PDFViewerApplication } from './app';

View File

@ -14,7 +14,7 @@
*/
import { mozL10n } from './ui_utils';
import { PasswordResponses } from './pdfjs';
import { PasswordResponses } from 'pdfjs-lib';
/**
* @typedef {Object} PasswordPromptOptions

View File

@ -16,7 +16,7 @@
import {
createObjectURL, createPromiseCapability, getFilenameFromUrl, PDFJS,
removeNullCharacters
} from './pdfjs';
} from 'pdfjs-lib';
/**
* @typedef {Object} PDFAttachmentViewerOptions

View File

@ -14,7 +14,7 @@
*/
import { cloneObj, getPDFFileNameFromURL, mozL10n } from './ui_utils';
import { createPromiseCapability } from './pdfjs';
import { createPromiseCapability } from 'pdfjs-lib';
const DEFAULT_FIELD_CONTENT = '-';

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createPromiseCapability } from './pdfjs';
import { createPromiseCapability } from 'pdfjs-lib';
import { scrollIntoView } from './ui_utils';
var FindStates = {

View File

@ -15,7 +15,7 @@
import {
addLinkAttributes, PDFJS, removeNullCharacters
} from './pdfjs';
} from 'pdfjs-lib';
const DEFAULT_TITLE = '\u2013';

View File

@ -20,7 +20,7 @@ import {
import {
createPromiseCapability, CustomStyle, PDFJS, RenderingCancelledException,
SVGGraphics
} from './pdfjs';
} from 'pdfjs-lib';
import { getGlobalEventBus } from './dom_events';
import { RenderingStates } from './pdf_rendering_queue';

View File

@ -15,7 +15,7 @@
import { CSS_UNITS, mozL10n } from './ui_utils';
import { PDFPrintServiceFactory, PDFViewerApplication } from './app';
import { PDFJS } from './pdfjs';
import { PDFJS } from 'pdfjs-lib';
let activeService = null;
let overlayManager = null;

View File

@ -13,7 +13,9 @@
* limitations under the License.
*/
import { createPromiseCapability, RenderingCancelledException } from './pdfjs';
import {
createPromiseCapability, RenderingCancelledException
} from 'pdfjs-lib';
import { getOutputScale, mozL10n } from './ui_utils';
import { RenderingStates } from './pdf_rendering_queue';

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { createPromiseCapability, PDFJS } from './pdfjs';
import { createPromiseCapability, PDFJS } from 'pdfjs-lib';
import {
CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, getVisibleElements,
MAX_AUTO_SCALE, RendererType, SCROLLBAR_PADDING, scrollIntoView,

View File

@ -16,38 +16,15 @@
'use strict';
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
var pdfjsLib;
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
if (typeof __pdfjsdev_webpack__ === 'undefined') {
if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
pdfjsLib = window['pdfjs-dist/build/pdf'];
} else if (typeof require === 'function') {
if (PDFJSDev.test('LIB')) {
pdfjsLib = require('../pdf.js');
} else {
pdfjsLib = require('../build/pdf.js');
}
} else {
throw new Error('Neither `require` nor `window` found');
}
var pdfjsLib;
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
if (typeof __pdfjsdev_webpack__ === 'undefined') {
if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
pdfjsLib = window['pdfjs-dist/build/pdf'];
} else if (typeof require === 'function') {
pdfjsLib = require('../build/pdf.js');
} else {
throw new Error('Neither `require` nor `window` found');
}
module.exports = pdfjsLib;
} else {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-web/pdfjs', ['exports', 'pdfjs/main_loader'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../src/main_loader.js'));
} else {
factory((root.pdfjsWebPDFJS = {}), root.pdfjsMainLoader);
}
}(this, function (exports, mainLoader) {
// Re-export all mainLoader members.
for (var i in mainLoader) {
if (Object.prototype.hasOwnProperty.call(mainLoader, i)) {
exports[i] = mainLoader[i];
}
}
}));
}
module.exports = pdfjsLib;

View File

@ -14,7 +14,7 @@
*/
import { getGlobalEventBus } from './dom_events';
import { renderTextLayer } from './pdfjs';
import { renderTextLayer } from 'pdfjs-lib';
var EXPAND_DIVS_TIMEOUT = 300; // ms

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { PDFJS } from './pdfjs';
import { PDFJS } from 'pdfjs-lib';
var CSS_UNITS = 96.0 / 72.0;
var DEFAULT_SCALE_VALUE = 'auto';