Skip to content

Commit

Permalink
Merge pull request #8462 from yurydelendik/rm=umd
Browse files Browse the repository at this point in the history
Removes last UMDs from the modules.
  • Loading branch information
yurydelendik authored May 31, 2017
2 parents 9637783 + 66c8893 commit 1e6f49b
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 224 deletions.
7 changes: 7 additions & 0 deletions external/builder/fixtures_esprima/importalias-expected.js
Original file line number Diff line number Diff line change
@@ -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');
5 changes: 5 additions & 0 deletions external/builder/fixtures_esprima/importalias.js
Original file line number Diff line number Diff line change
@@ -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');
5 changes: 0 additions & 5 deletions external/builder/fixtures_esprima/umd-expected.js

This file was deleted.

14 changes: 0 additions & 14 deletions external/builder/fixtures_esprima/umd.js

This file was deleted.

95 changes: 15 additions & 80 deletions external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions external/builder/test-fixtures_esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand All @@ -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: '.'}),
Expand Down
72 changes: 0 additions & 72 deletions src/main_loader.js

This file was deleted.

6 changes: 4 additions & 2 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions systemjs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
'*': {
Expand Down
2 changes: 1 addition & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
2 changes: 1 addition & 1 deletion web/download_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
2 changes: 1 addition & 1 deletion web/firefox_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { mozL10n } from './ui_utils';
import { PasswordResponses } from './pdfjs';
import { PasswordResponses } from 'pdfjs-lib';

/**
* @typedef {Object} PasswordPromptOptions
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import {
createObjectURL, createPromiseCapability, getFilenameFromUrl, PDFJS,
removeNullCharacters
} from './pdfjs';
} from 'pdfjs-lib';

/**
* @typedef {Object} PDFAttachmentViewerOptions
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { cloneObj, getPDFFileNameFromURL, mozL10n } from './ui_utils';
import { createPromiseCapability } from './pdfjs';
import { createPromiseCapability } from 'pdfjs-lib';

const DEFAULT_FIELD_CONTENT = '-';

Expand Down
2 changes: 1 addition & 1 deletion web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { createPromiseCapability } from './pdfjs';
import { createPromiseCapability } from 'pdfjs-lib';
import { scrollIntoView } from './ui_utils';

var FindStates = {
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import {
addLinkAttributes, PDFJS, removeNullCharacters
} from './pdfjs';
} from 'pdfjs-lib';

const DEFAULT_TITLE = '\u2013';

Expand Down
2 changes: 1 addition & 1 deletion web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Loading

0 comments on commit 1e6f49b

Please sign in to comment.