npm and error messages

This commit is contained in:
2018-10-27 03:51:47 -05:00
parent 692ab70565
commit 025a403027
29601 changed files with 2759363 additions and 14 deletions
+27
View File
@@ -0,0 +1,27 @@
/* @flow */
import { makeMap } from 'shared/util'
// The "unitary tag" means that the tag node and its children
// must be sent to the native together.
const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true)
function preTransformNode (el: ASTElement, options: CompilerOptions) {
if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) {
el.attrsMap.append = 'tree'
el.attrsList.push({ name: 'append', value: 'tree' })
}
if (el.attrsMap.append === 'tree') {
el.appendAsTree = true
}
}
function genData (el: ASTElement): string {
return el.appendAsTree ? `appendAsTree:true,` : ''
}
export default {
staticKeys: ['appendAsTree'],
preTransformNode,
genData
}
+73
View File
@@ -0,0 +1,73 @@
/* @flow */
import { parseText } from 'compiler/parser/text-parser'
import {
getAndRemoveAttr,
getBindingAttr,
baseWarn
} from 'compiler/helpers'
type StaticClassResult = {
dynamic: boolean,
classResult: string
};
function transformNode (el: ASTElement, options: CompilerOptions) {
const warn = options.warn || baseWarn
const staticClass = getAndRemoveAttr(el, 'class')
const { dynamic, classResult } = parseStaticClass(staticClass, options)
if (process.env.NODE_ENV !== 'production' && dynamic && staticClass) {
warn(
`class="${staticClass}": ` +
'Interpolation inside attributes has been deprecated. ' +
'Use v-bind or the colon shorthand instead.'
)
}
if (!dynamic && classResult) {
el.staticClass = classResult
}
const classBinding = getBindingAttr(el, 'class', false /* getStatic */)
if (classBinding) {
el.classBinding = classBinding
} else if (dynamic) {
el.classBinding = classResult
}
}
function genData (el: ASTElement): string {
let data = ''
if (el.staticClass) {
data += `staticClass:${el.staticClass},`
}
if (el.classBinding) {
data += `class:${el.classBinding},`
}
return data
}
function parseStaticClass (staticClass: ?string, options: CompilerOptions): StaticClassResult {
// "a b c" -> ["a", "b", "c"] => staticClass: ["a", "b", "c"]
// "a {{x}} c" -> ["a", x, "c"] => classBinding: '["a", x, "c"]'
let dynamic = false
let classResult = ''
if (staticClass) {
const classList = staticClass.trim().split(' ').map(name => {
const result = parseText(name, options.delimiters)
if (result) {
dynamic = true
return result.expression
}
return JSON.stringify(name)
})
if (classList.length) {
classResult = '[' + classList.join(',') + ']'
}
}
return { dynamic, classResult }
}
export default {
staticKeys: ['staticClass'],
transformNode,
genData
}
+13
View File
@@ -0,0 +1,13 @@
import klass from './class'
import style from './style'
import props from './props'
import append from './append'
import recycleList from './recycle-list/index'
export default [
recycleList,
klass,
style,
props,
append
]
+32
View File
@@ -0,0 +1,32 @@
/* @flow */
import { cached, camelize } from 'shared/util'
const normalize = cached(camelize)
function normalizeKeyName (str: string): string {
if (str.match(/^v\-/)) {
return str.replace(/(v-[a-z\-]+\:)([a-z\-]+)$/i, ($, directive, prop) => {
return directive + normalize(prop)
})
}
return normalize(str)
}
function transformNode (el: ASTElement, options: CompilerOptions) {
if (Array.isArray(el.attrsList)) {
el.attrsList.forEach(attr => {
if (attr.name && attr.name.match(/\-/)) {
const realName = normalizeKeyName(attr.name)
if (el.attrsMap) {
el.attrsMap[realName] = el.attrsMap[attr.name]
delete el.attrsMap[attr.name]
}
attr.name = realName
}
})
}
}
export default {
transformNode
}
@@ -0,0 +1,16 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
// mark component root nodes as
export function postTransformComponentRoot (
el: ASTElement,
options: WeexCompilerOptions
) {
if (!el.parent) {
// component root
addAttr(el, '@isComponentRoot', 'true')
addAttr(el, '@templateId', '_uid')
addAttr(el, '@componentProps', '$props || {}')
}
}
@@ -0,0 +1,16 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
import { RECYCLE_LIST_MARKER } from 'weex/util/index'
// mark components as inside recycle-list so that we know we need to invoke
// their special @render function instead of render in create-component.js
export function postTransformComponent (
el: ASTElement,
options: WeexCompilerOptions
) {
// $flow-disable-line (we know isReservedTag is there)
if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') {
addAttr(el, RECYCLE_LIST_MARKER, 'true')
}
}
@@ -0,0 +1,60 @@
/* @flow */
import { preTransformRecycleList } from './recycle-list'
import { postTransformComponent } from './component'
import { postTransformComponentRoot } from './component-root'
import { postTransformText } from './text'
import { preTransformVBind } from './v-bind'
import { preTransformVIf } from './v-if'
import { preTransformVFor } from './v-for'
import { postTransformVOn } from './v-on'
import { preTransformVOnce } from './v-once'
let currentRecycleList = null
function shouldCompile (el: ASTElement, options: WeexCompilerOptions) {
return options.recyclable ||
(currentRecycleList && el !== currentRecycleList)
}
function preTransformNode (el: ASTElement, options: WeexCompilerOptions) {
if (el.tag === 'recycle-list') {
preTransformRecycleList(el, options)
currentRecycleList = el
}
if (shouldCompile(el, options)) {
preTransformVBind(el, options)
preTransformVIf(el, options) // also v-else-if and v-else
preTransformVFor(el, options)
preTransformVOnce(el, options)
}
}
function transformNode (el: ASTElement, options: WeexCompilerOptions) {
if (shouldCompile(el, options)) {
// do nothing yet
}
}
function postTransformNode (el: ASTElement, options: WeexCompilerOptions) {
if (shouldCompile(el, options)) {
// mark child component in parent template
postTransformComponent(el, options)
// mark root in child component template
postTransformComponentRoot(el, options)
// <text>: transform children text into value attr
if (el.tag === 'text') {
postTransformText(el, options)
}
postTransformVOn(el, options)
}
if (el === currentRecycleList) {
currentRecycleList = null
}
}
export default {
preTransformNode,
transformNode,
postTransformNode
}
@@ -0,0 +1,50 @@
/* @flow */
import { parseFor } from 'compiler/parser/index'
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
/**
* Map the following syntax to corresponding attrs:
*
* <recycle-list for="(item, i) in longList" switch="cellType">
* <cell-slot case="A"> ... </cell-slot>
* <cell-slot case="B"> ... </cell-slot>
* </recycle-list>
*/
export function preTransformRecycleList (
el: ASTElement,
options: WeexCompilerOptions
) {
const exp = getAndRemoveAttr(el, 'for')
if (!exp) {
if (options.warn) {
options.warn(`Invalid <recycle-list> syntax: missing "for" expression.`)
}
return
}
const res = parseFor(exp)
if (!res) {
if (options.warn) {
options.warn(`Invalid <recycle-list> syntax: ${exp}.`)
}
return
}
addRawAttr(el, ':list-data', res.for)
addRawAttr(el, 'binding-expression', res.for)
addRawAttr(el, 'alias', res.alias)
if (res.iterator2) {
// (item, key, index) for object iteration
// is this even supported?
addRawAttr(el, 'index', res.iterator2)
} else if (res.iterator1) {
addRawAttr(el, 'index', res.iterator1)
}
const switchKey = getAndRemoveAttr(el, 'switch')
if (switchKey) {
addRawAttr(el, 'switch', switchKey)
}
}
@@ -0,0 +1,23 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
function genText (node: ASTNode) {
const value = node.type === 3
? node.text
: node.type === 2
? node.tokens.length === 1
? node.tokens[0]
: node.tokens
: ''
return JSON.stringify(value)
}
export function postTransformText (el: ASTElement, options: WeexCompilerOptions) {
// weex <text> can only contain text, so the parser
// always generates a single child.
if (el.children.length) {
addAttr(el, 'value', genText(el.children[0]))
el.children = []
}
}
@@ -0,0 +1,21 @@
/* @flow */
import { camelize } from 'shared/util'
import { generateBinding } from 'weex/util/parser'
import { bindRE } from 'compiler/parser/index'
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
function parseAttrName (name: string): string {
return camelize(name.replace(bindRE, ''))
}
export function preTransformVBind (el: ASTElement, options: WeexCompilerOptions) {
for (const attr in el.attrsMap) {
if (bindRE.test(attr)) {
const name: string = parseAttrName(attr)
const value = generateBinding(getAndRemoveAttr(el, attr))
delete el.attrsMap[attr]
addRawAttr(el, name, value)
}
}
}
@@ -0,0 +1,33 @@
/* @flow */
import { parseFor } from 'compiler/parser/index'
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
export function preTransformVFor (el: ASTElement, options: WeexCompilerOptions) {
const exp = getAndRemoveAttr(el, 'v-for')
if (!exp) {
return
}
const res = parseFor(exp)
if (!res) {
if (process.env.NODE_ENV !== 'production' && options.warn) {
options.warn(`Invalid v-for expression: ${exp}`)
}
return
}
const desc: Object = {
'@expression': res.for,
'@alias': res.alias
}
if (res.iterator2) {
desc['@key'] = res.iterator1
desc['@index'] = res.iterator2
} else {
desc['@index'] = res.iterator1
}
delete el.attrsMap['v-for']
addRawAttr(el, '[[repeat]]', desc)
}
@@ -0,0 +1,63 @@
/* @flow */
import { addIfCondition } from 'compiler/parser/index'
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
function hasConditionDirective (el: ASTElement): boolean {
for (const attr in el.attrsMap) {
if (/^v\-if|v\-else|v\-else\-if$/.test(attr)) {
return true
}
}
return false
}
function getPreviousConditions (el: ASTElement): Array<string> {
const conditions = []
if (el.parent && el.parent.children) {
for (let c = 0, n = el.parent.children.length; c < n; ++c) {
// $flow-disable-line
const ifConditions = el.parent.children[c].ifConditions
if (ifConditions) {
for (let i = 0, l = ifConditions.length; i < l; ++i) {
const condition = ifConditions[i]
if (condition && condition.exp) {
conditions.push(condition.exp)
}
}
}
}
}
return conditions
}
export function preTransformVIf (el: ASTElement, options: WeexCompilerOptions) {
if (hasConditionDirective(el)) {
let exp
const ifExp = getAndRemoveAttr(el, 'v-if', true /* remove from attrsMap */)
const elseifExp = getAndRemoveAttr(el, 'v-else-if', true)
// don't need the value, but remove it to avoid being generated as a
// custom directive
getAndRemoveAttr(el, 'v-else', true)
if (ifExp) {
exp = ifExp
addIfCondition(el, { exp: ifExp, block: el })
} else {
elseifExp && addIfCondition(el, { exp: elseifExp, block: el })
const prevConditions = getPreviousConditions(el)
if (prevConditions.length) {
const prevMatch = prevConditions.join(' || ')
exp = elseifExp
? `!(${prevMatch}) && (${elseifExp})` // v-else-if
: `!(${prevMatch})` // v-else
} else if (process.env.NODE_ENV !== 'production' && options.warn) {
options.warn(
`v-${elseifExp ? ('else-if="' + elseifExp + '"') : 'else'} ` +
`used on element <${el.tag}> without corresponding v-if.`
)
return
}
}
addRawAttr(el, '[[match]]', exp)
}
}
@@ -0,0 +1,25 @@
/* @flow */
const inlineStatementRE = /^\s*([A-Za-z_$0-9\['\."\]]+)*\s*\(\s*(([A-Za-z_$0-9\['\."\]]+)?(\s*,\s*([A-Za-z_$0-9\['\."\]]+))*)\s*\)$/
function parseHandlerParams (handler: ASTElementHandler) {
const res = inlineStatementRE.exec(handler.value)
if (res && res[2]) {
handler.params = res[2].split(/\s*,\s*/)
}
}
export function postTransformVOn (el: ASTElement, options: WeexCompilerOptions) {
const events: ASTElementHandlers | void = el.events
if (!events) {
return
}
for (const name in events) {
const handler: ASTElementHandler | Array<ASTElementHandler> = events[name]
if (Array.isArray(handler)) {
handler.map(fn => parseHandlerParams(fn))
} else {
parseHandlerParams(handler)
}
}
}
@@ -0,0 +1,19 @@
/* @flow */
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
function containVOnce (el: ASTElement): boolean {
for (const attr in el.attrsMap) {
if (/^v\-once$/i.test(attr)) {
return true
}
}
return false
}
export function preTransformVOnce (el: ASTElement, options: WeexCompilerOptions) {
if (containVOnce(el)) {
getAndRemoveAttr(el, 'v-once', true)
addRawAttr(el, '[[once]]', true)
}
}
+86
View File
@@ -0,0 +1,86 @@
/* @flow */
import { cached, camelize, isPlainObject } from 'shared/util'
import { parseText } from 'compiler/parser/text-parser'
import {
getAndRemoveAttr,
getBindingAttr,
baseWarn
} from 'compiler/helpers'
type StaticStyleResult = {
dynamic: boolean,
styleResult: string | Object | void
};
const normalize = cached(camelize)
function transformNode (el: ASTElement, options: CompilerOptions) {
const warn = options.warn || baseWarn
const staticStyle = getAndRemoveAttr(el, 'style')
const { dynamic, styleResult } = parseStaticStyle(staticStyle, options)
if (process.env.NODE_ENV !== 'production' && dynamic) {
warn(
`style="${String(staticStyle)}": ` +
'Interpolation inside attributes has been deprecated. ' +
'Use v-bind or the colon shorthand instead.'
)
}
if (!dynamic && styleResult) {
// $flow-disable-line
el.staticStyle = styleResult
}
const styleBinding = getBindingAttr(el, 'style', false /* getStatic */)
if (styleBinding) {
el.styleBinding = styleBinding
} else if (dynamic) {
// $flow-disable-line
el.styleBinding = styleResult
}
}
function genData (el: ASTElement): string {
let data = ''
if (el.staticStyle) {
data += `staticStyle:${el.staticStyle},`
}
if (el.styleBinding) {
data += `style:${el.styleBinding},`
}
return data
}
function parseStaticStyle (staticStyle: ?string, options: CompilerOptions): StaticStyleResult {
// "width: 200px; height: 200px;" -> {width: 200, height: 200}
// "width: 200px; height: {{y}}" -> {width: 200, height: y}
let dynamic = false
let styleResult = ''
if (typeof staticStyle === 'string') {
const styleList = staticStyle.trim().split(';').map(style => {
const result = style.trim().split(':')
if (result.length !== 2) {
return
}
const key = normalize(result[0].trim())
const value = result[1].trim()
const dynamicValue = parseText(value, options.delimiters)
if (dynamicValue) {
dynamic = true
return key + ':' + dynamicValue.expression
}
return key + ':' + JSON.stringify(value)
}).filter(result => result)
if (styleList.length) {
styleResult = '{' + styleList.join(',') + '}'
}
} else if (isPlainObject(staticStyle)) {
styleResult = JSON.stringify(staticStyle) || ''
}
return { dynamic, styleResult }
}
export default {
staticKeys: ['staticStyle'],
transformNode,
genData
}