 module.exports = (pattern, element) ->
   housing = element.housing
   leadCount = housing.leadCount ? 2*(housing.rowCount + housing.columnCount)
-  if housing.tabWidth? and housing.tabLength then ++leadCount
+  hasTab = housing.tabWidth? and housing.tabLength?
+  if hasTab then ++leadCount
   height = housing.height.max ? housing.height
   pattern.name ?= sprintf "%sQFN%dP%dX%dX%d-%d",
     if housing.pullBack? then 'P' else '',


  # Courtyard
  courtyard = padParams.courtyard
  x = bodyWidth/2 + courtyard
  y = bodyLength/2 + courtyard

  pattern
    .layer 'topCourtyard'

    layer: ['topCopper', 'topMask', 'topPaste']

  quad pattern, padParams

  if hasTab
    housing.tabOffset ?= '0, 0'
    [x, y] = housing.tabOffset.replace(/\s+/g, '').split(',').map((a) => parseFloat(a))

    tabNumber = leadCount
    tabPad =
      type: 'smd'
      shape: 'rectangle'
      width: housing.tabWidth.nom
      height: housing.tabLength.nom
      layer: ['topCopper', 'topMask', 'topPaste']
      x: x
      y: y
    pattern.pad tabNumber, tabPad

  firstPad = pattern.pads[1]
  lastPad = pattern.pads[2*(padParams.rowCount + padParams.columnCount)]
